Difference between revisions of "Rust-Programming-Language/C2/Hello-World-using-Cargo/English"
| Line 4: | Line 4: | ||
|| '''Narration''' | || '''Narration''' | ||
|- | |- | ||
| − | || | + | || <div style="color:#000000;">Show Slide: </div> |
| − | '''Title Slide''' | + | <div style="color:#000000;">'''Title Slide'''</div> |
| − | || Welcome to the Spoken tutorial on '''Hello World using Cargo''' | + | || <span style="color:#000000;">Welcome to the Spoken tutorial on </span><span style="color:#000000;">'''Hello World using Cargo.'''</span> |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || | + | || <div style="color:#000000;">Show Slide: </div> |
| − | '''Learning Objectives''' | + | <div style="color:#000000;">'''Learning Objectives'''</div> |
|| In this tutorial, we will learn how to | || In this tutorial, we will learn how to | ||
| − | * Create a cargo project | + | * <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Create a cargo project</div> |
| − | * Write a Hello world rust program | + | * <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Write a Hello world rust program</div> |
| − | * Compile and Run the cargo project | + | * <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#000000;">Compile and Run the </span>cargo project</div> |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || | + | || <div style="color:#000000;">Show Slide:</div> |
| − | '''System Requirements''' | + | <div style="color:#000000;">'''System Requirements'''</div> |
| − | || | + | || T<span style="color:#000000;">his tutorial</span> is recorded <span style="color:#000000;">using</span> |
| − | * Ubuntu Linux OS version 22.04 | + | * <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Ubuntu Linux OS version 22.04</div> |
| − | * Rust version 1.80.0 | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Rust version 1.80.0 </div> |
| − | * Visual studio code version 1.19.0 | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Visual studio code version 1.19.0</div> |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || | + | || Show slide: |
| − | + | Prerequisite | |
|| To follow this tutorial, | || To follow this tutorial, | ||
| − | * You must have basic knowledge of any programming language | + | * <div style="margin-left:1.27cm;margin-right:0cm;">You must have basic knowledge of any programming language</div> |
| − | * You should also have '''Rust '''installed on your system. | + | * <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;">You should also have </span><span style="background-color:#ffffff;">'''Rust '''</span><span style="background-color:#ffffff;">installed on your system.</span></div> |
| − | + | ||
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || ''' | + | || <div style="color:#000000;">''' Slide: '''</div> |
| − | '''About Cargo''' | + | <div style="color:#000000;">'''About Cargo'''</div> |
|| | || | ||
| − | * '''Cargo '''is a '''Rust build system''' and '''package manager''' | + | * <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#000000;">'''Cargo '''</span><span style="color:#000000;">is a </span><span style="color:#000000;">'''Rust build system'''</span><span style="color:#000000;"> and </span><span style="color:#000000;">'''package manager'''</span></div> |
| − | * Cargo handles the compilation process and automates the building of your project. | + | * <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#000000;">Cargo handles the compilation process</span> and automates<span style="color:#000000;"> the building of </span>your project.</div> |
| − | * Cargo allows you | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Cargo allows you at add and manage external libraries</div> |
| − | * In the | + | * <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#000000;">In the Cargo.toml</span><span style="color:#000000;">''' '''</span><span style="color:#000000;">file, you can list your dependencies.</span></div> |
| − | * Complex '''Rust '''programs need these '''dependencies''' to develop '''Rust projects''' | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Complex '''Rust '''programs need these '''dependencies''' to develop '''Rust projects'''<span style="color:#252525;">.</span></div> |
| − | + | ||
| − | + | ||
| − | + | |- style="border:1pt solid #252525;padding:0cm;" | |
| − | || | + | || <div style="color:#000000;">Open Visual code editor</div> |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | || <span style="color:#000000;">Let us open the </span><span style="color:#000000;">'''Visual Studio Code editor.'''</span> | |
| − | + | |- style="border:1pt solid #252525;padding:0cm;" | |
| − | || Let us open the '''Visual Studio Code editor.''' | + | || <span style="color:#000000;">click on </span><span style="color:#000000;">'''terminal'''</span><span style="color:#000000;"> </span><span style="color:#000000;">and select</span><span style="color:#000000;"> </span><span style="color:#000000;">'''New Terminal.'''</span> |
| − | |- | + | || <span style="color:#000000;">In the menu bar, click on </span><span style="color:#000000;">'''terminal'''</span><span style="color:#000000;"> </span><span style="color:#000000;">and select</span><span style="color:#000000;"> </span><span style="color:#000000;">'''New Terminal.'''</span> |
| − | || | + | |
| − | || In the menu bar, click on '''terminal''' and select '''New Terminal''' | + | |
| − | We can see a terminal window at the bottom. | + | <div style="color:#000000;">We can see a terminal window at the bottom.</div> |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || Create direcotry '''MyRustProject''' | + | || <span style="color:#000000;">Create direcotry </span><span style="color:#000000;">'''MyRustProject'''</span> |
| − | >mkdir Desktop/MyRustProject | + | <div style="color:#000000;">>mkdir Desktop/MyRustProject</div> |
| − | >cd Desktop/MyRustProject | + | <div style="color:#000000;">>cd Desktop/MyRustProject</div> |
| − | || Let us create a directory '''MyRustProject''' on the ''' | + | || <span style="color:#000000;">Let us create a directory </span><span style="color:#000000;">'''MyRustProject'''</span><span style="color:#000000;"> </span>on the<span style="color:#000000;"> desktop.</span><span style="color:#000000;">In the terminal</span>, <span style="color:#000000;">type as shown to create a directory </span><span style="color:#000000;">'''MyRustProject'''</span>. |
| − | + | We will save all the Rust Projects in this directory required for this series. | |
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | || <div style="color:#000000;">Type</div> | ||
| − | + | <span style="color:#000000;">></span><span style="color:#000000;">'''cargo new hellowor</span>ld''' | |
| − | + | || <span style="color:#000000;">Type the command </span><span style="color:#000000;">'''cargo new hellowor</span>ld''' | |
| − | || Type | + | |
| − | > | + | <div style="color:#000000;">A binary cargo application has been created.</div> |
| − | || | + | |- style="border:1pt solid #252525;padding:0cm;" |
| + | || <div style="color:#000000;">Click File>> Open folder</div> | ||
| − | + | <div style="color:#000000;">Select hello folder under MyRustPRoject</div> | |
| − | + | || <span style="background-color:#ffffff;color:#000000;">Open the created project by clicking on the </span><span style="background-color:#ffffff;color:#000000;">'''File'''</span><span style="background-color:#ffffff;color:#000000;"> menu in the menu bar and then </span><span style="background-color:#ffffff;color:#000000;">'''Open folder.'''</span> | |
| − | + | ||
| − | + | <span style="background-color:#ffffff;color:#000000;">Go to </span><span style="background-color:#ffffff;color:#000000;">'''Desktop'''</span><span style="background-color:#ffffff;color:#000000;"> and then select </span><span style="background-color:#ffffff;color:#000000;">'''MyRustProject'''</span><span style="background-color:#ffffff;color:#000000;">.</span> | |
| − | + | <span style="background-color:#ffffff;color:#000000;">Locate the </span><span style="color:#000000;">'''helloworld'''</span><span style="background-color:#ffffff;color:#000000;"> folder.</span> | |
| − | + | <span style="background-color:#ffffff;color:#000000;">Then click on the </span><span style="background-color:#ffffff;color:#000000;">'''open'''</span><span style="background-color:#ffffff;color:#000000;"> button at the top right corner.</span> | |
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | | style="color:#000000;" | '''Click src folder> main.rs''' | ||
| + | || <span style="background-color:#ffffff;color:#000000;">In the left panel,under the </span><span style="background-color:#ffffff;color:#000000;">'''EXPLORER'''</span><span style="background-color:#ffffff;color:#000000;"> section, expand the project </span><span style="color:#000000;">'''hello'''</span><span style="background-color:#ffffff;color:#000000;"> by clicking on it.</span> | ||
| − | + | <span style="color:#000000;">Click the </span><span style="color:#000000;">'''src'''</span><span style="color:#000000;"> folder, and you can see that a file called </span><span style="color:#000000;">'''main.rs'''</span><span style="color:#000000;"> is created.</span> | |
| − | + | Click on it to open the file. | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | <span style="color:#000000;">All the code has to be run using this particular file </span><span style="color:#000000;">'''main.rs.'''</span> | |
| − | + | <div style="color:#000000;">By default, we can see a hello world program on the right panel.</div> | |
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | | style="color:#000000;" | | ||
| + | | style="color:#000000;" | Let us see the Rust program structure. | ||
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | || <div style="color:#000000;">'''Highlight according to narration.'''</div> | ||
| − | + | <div style="color:#000000;">'''fn main() {'''</div> | |
| − | + | <div style="color:#000000;">'''println!("Hello, World!");'''</div> | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | ''' | + | <div style="color:#000000;">'''}'''</div> |
| − | + | || <span style="color:#000000;">Every Rust program </span>starts<span style="color:#000000;"> with this </span><span style="color:#000000;">'''`main`'''</span><span style="color:#000000;"> function.</span> | |
| − | '''}''' | + | <span style="color:#000000;">Inside the curly braces </span><span style="color:#000000;">'''`{ ... }`'''</span><span style="color:#000000;"> </span><span style="color:#000000;">'''Println '''</span><span style="color:#000000;">command prints the text hello world.</span> |
| − | + | <span style="color:#000000;">The </span><span style="color:#000000;">'''semicolon `;`'''</span><span style="color:#000000;"> at the end indicates the end of the command.</span> | |
| − | + | <span style="color:#000000;">Save the file by pressing </span><span style="color:#000000;">'''Ctrl + S.'''</span> | |
| − | + | <div style="color:#000000;">Let us compile and run the program.</div> | |
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | | style="color:#000000;" | Click on terminal> new terminal | ||
| + | || <span style="color:#000000;">In the menu bar, click on </span><span style="color:#000000;">'''terminal'''</span><span style="color:#000000;"> and select </span><span style="color:#000000;">'''New Terminal.'''</span> | ||
| − | + | Make sure that we are inside the cargo project .i.e '''helloworld''' | |
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | | style="color:#000000;" | '''> cargo build''' | ||
| + | || <span style="color:#000000;">In the terminal. type </span><span style="color:#000000;">'''cargo build '''</span><span style="color:#000000;">to compile the Cargo project.</span> | ||
| − | + | <div style="color:#000000;">When successfully compiled, we see a finished message.</div> | |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || | + | | style="color:#000000;" | '''>cargo run''' |
| − | + | || <div style="color:#000000;">As the project is compiled successfully, it’s time to run the project.</div> | |
| − | + | <span style="color:#000000;">Then type </span><span style="color:#000000;">'''cargo run'''</span> | |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || ''' | + | | style="color:#000000;" | '''Point to the output''' |
| − | || | + | | style="color:#000000;" | Now we see Hello world! printed in the terminal. |
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | || <div style="color:#000000;">'''Type '''</div> | ||
| − | + | <span style="background-color:#ffffff;">'''Println!</span><span style="background-color:#ffffff;color:#000000;">(“Welcome to Rust Spoken Tutorial”);'''</span> | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | <div style="color:#000000;">'''Press Ctrl+s'''</div> | |
| − | + | || <div style="color:#000000;">Let us add one more print statement in the program.</div> | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | '''Press Ctrl+ | + | |
| − | || Let us add one more print statement in the program. | + | |
In the code window, type a print statement “welcome to Rust spoken tutorial” as shown. | In the code window, type a print statement “welcome to Rust spoken tutorial” as shown. | ||
| − | Press | + | <span style="color:#000000;">Press </span>c<span style="color:#000000;">trl+s to save the file.</span> |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || '''> cargo run''' | + | | style="color:#000000;" | '''> cargo run''' |
| − | || | + | || <div style="color:#000000;"></div> |
| − | We can see both the text messages as output. | + | <span style="color:#000000;">In the terminal, type</span><span style="color:#252525;"> </span><span style="color:#252525;">'''cargo run'''</span> |
| − | |- | + | |
| − | || | + | <span style="color:#000000;">We can see both the text </span>messages<span style="color:#000000;"> as output.</span> |
| − | || After switching back, I directly did a | + | |- style="border:1pt solid #252525;padding:0cm;" |
| + | | style="color:#000000;" | | ||
| + | || After switching back, I directly did a cargo run without compiling the project again. | ||
Did you notice that? | Did you notice that? | ||
| − | When we do a '''cargo run, ''' the '''package manager '''will '''build '''again and '''run '''the '''project'''. | + | When we do a '''cargo run, '''the '''package manager '''will '''build '''again and '''run '''the '''project'''. |
| − | So going forward, we can directly use '''cargo run ''' to '''build '''and '''run '''the '''project '''in one go. | + | So going forward, we can directly use '''cargo run '''to '''build '''and '''run '''the '''project '''in one go. |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || '''Click on cargo.toml''' | + | | style="color:#000000;" | '''Click on cargo.toml''' |
| − | || In the left panel, open the file '''Cargo.toml.''' | + | || <span style="background-color:#ffffff;color:#000000;">In the left panel, open the file </span><span style="background-color:#ffffff;color:#000000;">'''Cargo.toml.'''</span> |
| − | We | + | <span style="background-color:#ffffff;color:#000000;">We see two sections namely </span><span style="background-color:#ffffff;color:#000000;">'''package'''</span><span style="background-color:#ffffff;color:#000000;"> and </span><span style="background-color:#ffffff;color:#000000;">'''dependencies.'''</span> |
| − | This is where we can write all the project related information like name, version, authors, edition. | + | <div style="color:#000000;">This is where we can write all the project related information like name, version, authors, edition.</div> |
| − | We can even mention dependencies which the project depends upon. | + | <div style="color:#000000;">We can even mention dependencies which the project depends upon.</div> |
| − | |- | + | |- style="border:1pt solid #252525;padding:0cm;" |
| − | || | + | || <div style="color:#000000;">Show Slide:</div> |
| − | '''Summary''' | + | <div style="color:#000000;">'''Summary'''</div> |
| − | || This brings us to the end of this tutorial. | + | || <div style="color:#000000;">This brings us to the end of this tutorial.</div> |
| − | Let us summarize. | + | <div style="color:#000000;">Let us summarize. </div> |
| + | |- style="border:1pt solid #252525;padding:0cm;" | ||
| + | || Slide: | ||
| − | + | Assignment | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
|| As an assignment, | || As an assignment, | ||
| − | * Create a cargo project named''' assignment''' | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Create a cargo project named''' assignment'''</div> |
| − | * Print - “ Welcome to Rust Assignment” | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Print - “ Welcome to Rust Assignment”</div> |
| − | * Compile and execute the project | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Compile and execute the project</div> |
| − | * | + | * <div style="margin-left:1.27cm;margin-right:0cm;">Observe the output in the Terminal</div> |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | |- style="border:1pt solid #252525;padding-top:0.176cm;padding-bottom:0.176cm;padding-left:0.123cm;padding-right:0.176cm;" | |
| − | || | + | || <div style="color:#000000;">Show Slide: </div> |
| − | Thank you for joining. | + | <div style="color:#000000;">'''Thank you'''</div> |
| + | || <span style="color:#000000;">Thank you for joining.</span> | ||
|- | |- | ||
|} | |} | ||
Revision as of 15:02, 10 July 2025
| Visual Cue | Narration |
| Show Slide:
Title Slide
|
Welcome to the Spoken tutorial on Hello World using Cargo. |
| Show Slide:
Learning Objectives
|
In this tutorial, we will learn how to
|
| Show Slide:
System Requirements
|
This tutorial is recorded using
|
| Show slide:
Prerequisite |
To follow this tutorial,
|
| Slide:
About Cargo
|
|
| Open Visual code editor
|
Let us open the Visual Studio Code editor. |
| click on terminal and select New Terminal. | In the menu bar, click on terminal and select New Terminal.
We can see a terminal window at the bottom.
|
| Create direcotry MyRustProject
>mkdir Desktop/MyRustProject
>cd Desktop/MyRustProject
|
Let us create a directory MyRustProject on the desktop.In the terminal, type as shown to create a directory MyRustProject.
We will save all the Rust Projects in this directory required for this series. |
| Type
>cargo new helloworld |
Type the command cargo new helloworld
A binary cargo application has been created.
|
| Click File>> Open folder
Select hello folder under MyRustPRoject
|
Open the created project by clicking on the File menu in the menu bar and then Open folder.
Go to Desktop and then select MyRustProject. Locate the helloworld folder. Then click on the open button at the top right corner. |
| Click src folder> main.rs | In the left panel,under the EXPLORER section, expand the project hello by clicking on it.
Click the src folder, and you can see that a file called main.rs is created. Click on it to open the file. All the code has to be run using this particular file main.rs. By default, we can see a hello world program on the right panel.
|
| Let us see the Rust program structure. | |
| Highlight according to narration.
fn main() {
println!("Hello, World!");
}
|
Every Rust program starts with this `main` function.
Inside the curly braces `{ ... }` Println command prints the text hello world. The semicolon `;` at the end indicates the end of the command. Save the file by pressing Ctrl + S. Let us compile and run the program.
|
| Click on terminal> new terminal | In the menu bar, click on terminal and select New Terminal.
Make sure that we are inside the cargo project .i.e helloworld |
| > cargo build | In the terminal. type cargo build to compile the Cargo project.
When successfully compiled, we see a finished message.
|
| >cargo run | As the project is compiled successfully, it’s time to run the project.
Then type cargo run |
| Point to the output | Now we see Hello world! printed in the terminal. |
| Type
Println!(“Welcome to Rust Spoken Tutorial”); Press Ctrl+s
|
Let us add one more print statement in the program.
In the code window, type a print statement “welcome to Rust spoken tutorial” as shown. Press ctrl+s to save the file. |
| > cargo run |
In the terminal, type cargo run We can see both the text messages as output. |
| After switching back, I directly did a cargo run without compiling the project again.
Did you notice that? When we do a cargo run, the package manager will build again and run the project. So going forward, we can directly use cargo run to build and run the project in one go. | |
| Click on cargo.toml | In the left panel, open the file Cargo.toml.
We see two sections namely package and dependencies. This is where we can write all the project related information like name, version, authors, edition.
We can even mention dependencies which the project depends upon.
|
| Show Slide:
Summary
|
This brings us to the end of this tutorial.
Let us summarize.
|
| Slide:
Assignment |
As an assignment,
|
| Show Slide:
Thank you
|
Thank you for joining. |