Getting to Hello World

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

Lesson Transcript

  • [00:00 - 00:12] Now that we have Rust installed, we can write a simple hello world program. To do that, we'll just make a new directory here and call it hello.

  • [00:13 - 00:25] Change into that directory and open it up in VS code. I'll be using VS code just because it's easier and familiar to most users and it has really good Rust support.

  • [00:26 - 00:41] To make our Rust environment a little bit nicer, we'll go ahead and install the Rust extension. This just gives us basic code completion and type hinting in the editor itself.

  • [00:42 - 00:59] So we'll go here and create a new file and call it hello.rs. Inside of hello.rs, we need to create a main function.

  • [01:00 - 01:03] The main function is a special function Rust. This is similar to other compiled languages.

  • [01:04 - 01:13] It tells the compiler that this is the entry point to our program. It's a little bit different from JavaScript, which is usually interpreted by either node or the browser.

  • [01:14 - 01:32] JavaScript doesn't need a main function because it isn't compiled ahead of time , like Rust is. Inside of our main function, we can go ahead and add a println and we'll put hello world.

  • [01:33 - 01:42] The println command is the Rust equivalent to console log in JavaScript. There are some differences.

  • [01:43 - 01:50] For example, you have to pass a string. As the first argument, you can't pass something like a number, for example.

  • [01:51 - 02:01] We'll get into that into why a little bit later. For now, we'll just go ahead and print out hello world.

  • [02:02 - 02:23] We'll save this file, go back to our terminal, and run Rust C and target that hello.rs file. You can see that we have that compiled binary that is an output.

  • [02:24 - 02:38] Rust C compilation is similar to, if you're familiar with the TypeScript ecosystem, it's similar to the TSC or the TypeScript compiler. That transforms TypeScript into JavaScript.

  • [02:39 - 03:03] The Rust compiler takes our Rust source code and transforms it into a binary format which is directly executable by our host machine. Babel is sort of like this as well, but instead of binary format, it takes modern JavaScript and compile it or transpiles it into older JavaScript that will run in more environments like older browsers.

  • [03:04 - 03:07] We have our output file here. Hello.

  • [03:08 - 03:13] We can run that by calling dot slash hello. We can see that hello world is printed to the console.

  • [03:14 - 03:20] [ Silence ]

  • [00:00 - 00:12] Now that we have Rust installed, we can write a simple hello world program. To do that, we'll just make a new directory here and call it hello.

    [00:13 - 00:25] Change into that directory and open it up in VS code. I'll be using VS code just because it's easier and familiar to most users and it has really good Rust support.

    [00:26 - 00:41] To make our Rust environment a little bit nicer, we'll go ahead and install the Rust extension. This just gives us basic code completion and type hinting in the editor itself.

    [00:42 - 00:59] So we'll go here and create a new file and call it hello.rs. Inside of hello.rs, we need to create a main function.

    [01:00 - 01:03] The main function is a special function Rust. This is similar to other compiled languages.

    [01:04 - 01:13] It tells the compiler that this is the entry point to our program. It's a little bit different from JavaScript, which is usually interpreted by either node or the browser.

    [01:14 - 01:32] JavaScript doesn't need a main function because it isn't compiled ahead of time , like Rust is. Inside of our main function, we can go ahead and add a println and we'll put hello world.

    [01:33 - 01:42] The println command is the Rust equivalent to console log in JavaScript. There are some differences.

    [01:43 - 01:50] For example, you have to pass a string. As the first argument, you can't pass something like a number, for example.

    [01:51 - 02:01] We'll get into that into why a little bit later. For now, we'll just go ahead and print out hello world.

    [02:02 - 02:23] We'll save this file, go back to our terminal, and run Rust C and target that hello.rs file. You can see that we have that compiled binary that is an output.

    [02:24 - 02:38] Rust C compilation is similar to, if you're familiar with the TypeScript ecosystem, it's similar to the TSC or the TypeScript compiler. That transforms TypeScript into JavaScript.

    [02:39 - 03:03] The Rust compiler takes our Rust source code and transforms it into a binary format which is directly executable by our host machine. Babel is sort of like this as well, but instead of binary format, it takes modern JavaScript and compile it or transpiles it into older JavaScript that will run in more environments like older browsers.

    [03:04 - 03:07] We have our output file here. Hello.

    [03:08 - 03:13] We can run that by calling dot slash hello. We can see that hello world is printed to the console.

    [03:14 - 03:20] [ Silence ]