Difference between revisions of "Rust-Programming-Language/C2/Hello-World-using-Cargo/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| border="1" |- || '''Visual Cue''' || '''Narration''' |- || <div style="color:#000000;">Show Slide: </div> <div style="color:#000000;">'''Title Slide'''</div> || <span sty...")
 
Line 4: Line 4:
 
|| '''Narration'''
 
|| '''Narration'''
 
|-
 
|-
|| <div style="color:#000000;">Show Slide: </div>
+
|| '''Show Slide: '''
  
<div style="color:#000000;">'''Title Slide'''</div>
+
'''Title Slide'''
  
|| <span style="color:#000000;">Welcome to the Spoken tutorial on </span><span style="color:#000000;">'''Hello World using Cargo.'''</span>
+
|| Welcome to the Spoken tutorial on '''Hello World using Cargo'''.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| <div style="color:#000000;">Show Slide: </div>
+
|| '''Show Slide: '''
  
<div style="color:#000000;">'''Learning Objectives'''</div>
+
'''Learning Objectives'''
 
|| In this tutorial, we will learn how to
 
|| In this tutorial, we will learn how to
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Create a cargo project</div>
+
* Create a cargo project
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Write a Hello world rust program</div>
+
* Write a Hello world rust program
* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#000000;">Compile and Run the </span>cargo project</div>
+
* Compile and Run the cargo project
  
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| <div style="color:#000000;">Show Slide:</div>
+
|| '''Show Slide: '''
  
<div style="color:#000000;">'''System Requirements'''</div>
+
'''System Requirements'''
|| T<span style="color:#000000;">his tutorial</span> is recorded <span style="color:#000000;">using</span>
+
|| This tutorial is recorded using
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Ubuntu Linux OS version 22.04</div>
+
* Ubuntu Linux OS version 22.04
* <div style="margin-left:1.27cm;margin-right:0cm;">Rust version 1.80.0 </div>
+
* Rust version 1.80.0  
* <div style="margin-left:1.27cm;margin-right:0cm;">Visual studio code version 1.19.0</div>
+
* Visual studio code version 1.19.0
  
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| Show slide:
+
|| '''Show Slide: '''
  
Prerequisite
+
'''Prerequisites'''
 
|| To follow this tutorial,
 
|| To follow this tutorial,
* <div style="margin-left:1.27cm;margin-right:0cm;">You must have basic knowledge of any programming language</div>
+
* You must have basic knowledge of any programming language
* <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>
+
* You should also have '''Rust '''installed on your system.
* <div style="margin-left:1.27cm;margin-right:0cm;">If not, go through the relevant tutorials on this website.</div>
+
* If not, go through the relevant tutorials on this website.
  
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| <div style="color:#000000;">'''&nbsp;Slide: '''</div>
+
|| '''Show Slide: '''
  
<div style="color:#000000;">'''About Cargo'''</div>
+
'''About Cargo'''
  
 
||  
 
||  
* <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 '''is a '''Rust build system''' and '''package manager'''
* <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 handles the compilation process and automates the building of your project.
* <div style="margin-left:1.27cm;margin-right:0cm;">Cargo allows you to add and manage external libraries to your project</div>
+
* Cargo allows you to add and manage external libraries to your project
* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#000000;">In the </span><span style="color:#000000;">'''Cargo.toml</span><span style="color:#000000;"> '''</span><span style="color:#000000;">file, you can list your dependencies.</span></div>
+
* In the '''Cargo.toml '''file, you can list your dependencies.
* <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>
+
* Complex '''Rust '''programs need these '''dependencies''' to develop '''Rust projects'''
 
+
|-
|- style="border:1pt solid #252525;padding:0cm;"
+
|| '''Show Slide:'''
|| '''Slide:'''
+
  
 
'''Cargo commands'''
 
'''Cargo commands'''
|| <div style="color:#000000;">Let’s begin understanding the commands first.</div>
+
|| Let’s begin understanding the commands first.
* <div style="color:#000000;margin-left:1.905cm;margin-right:0cm;">To create a Cargo project use '''cargo new project name'''</div>
+
* To create a Cargo project use '''cargo new project name'''
* <div style="color:#000000;margin-left:1.905cm;margin-right:0cm;">To compile, use '''cargo build''' inside the created project.</div>
+
* To compile, use '''cargo build''' inside the created project.
* <div style="color:#000000;margin-left:1.905cm;margin-right:0cm;">To run, use '''cargo run''' inside the project</div>
+
* To run, use '''cargo run''' inside the project
  
<div style="color:#000000;"></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;"
+
|| Open '''Visual 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>
+
|| Let us open the '''Visual Studio Code editor.'''
|| <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>
+
|-
 +
|| click on '''terminal''' and select '''New Terminal.'''
 +
|| In the menu bar, click on '''terminal''' and select '''New Terminal.'''
  
<div style="color:#000000;">We can see a terminal window at the bottom.</div>
+
We can see a terminal window at the bottom.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| <span style="color:#000000;">Create direcotry </span><span style="color:#000000;">'''MyRustProject'''</span>
+
|| Create direcotry '''MyRustProject'''
  
<div style="color:#000000;">>mkdir Desktop/MyRustProject</div>
+
>mkdir Desktop/MyRustProject
  
<div style="color:#000000;">>cd Desktop/MyRustProject</div>
+
>cd Desktop/MyRustProject
  
|| <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.In the terminal</span>, <span style="color:#000000;">type as shown to create a directory </span><span style="color:#000000;">'''MyRustProject'''</span>.
+
|| Let us create a directory '''MyRustProject''' on the Desktop.
  
We will save all the Rust Projects in this directory required for this series.
+
In the terminal, type as shown to create a directory '''MyRustProject'''.
|- 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'''
+
We will save all the '''Rust''' Projects in this directory required for this series.
|| <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>
+
>'''cargo new helloworld'''
|- style="border:1pt solid #252525;padding:0cm;"
+
|| Type the command '''cargo new helloworld'''.
|| <div style="color:#000000;">Click File>> Open folder</div>
+
  
<div style="color:#000000;">Select hello folder under MyRustPRoject</div>
+
A binary '''cargo''' application has been created.
|| <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>
+
|-
 +
|| Click File>> Open folder
  
<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>
+
Select hello folder under MyRustPRoject
 +
|| Open the created project by clicking on the '''File''' menu in the menu bar and then '''Open folder.'''
  
<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>
+
Go to '''Desktop''' and then select '''MyRustProject'''.
  
<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>
+
Locate the '''helloworld''' folder.
|- 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="color:#000000;">world'''</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>
+
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.
 
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>
+
All the code has to be run using this particular file '''main.rs.'''
  
<div style="color:#000000;">By default, we can see a hello world program on the right panel.</div>
+
By default, we can see a hello world program on the right panel.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
| style="color:#000000;" |  
+
||  
| style="color:#000000;" | Let us see the Rust program structure.
+
|| Let us see the '''Rust''' program structure.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| <div style="color:#000000;">'''Highlight according to narration.'''</div>
+
|| '''Highlight according to narration.'''
  
<div style="color:#000000;">'''fn main() {'''</div>
+
'''fn main() {'''
  
<div style="color:#000000;">'''println!("Hello, World!");'''</div>
+
'''println!("Hello, World!");'''
  
<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>
+
|| Every Rust program starts with this '''`main`''' function.
  
<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>
+
Inside the curly braces '''`{ ... }`''' '''Println '''command prints the text hello world.
  
<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>
+
The '''semicolon `;`''' at the end indicates the end of the command.
  
<span style="color:#000000;">Save the file by pressing </span><span style="color:#000000;">'''Ctrl + S.'''</span>
+
Save the file by pressing '''Ctrl + S.'''
  
<div style="color:#000000;">Let us compile and run the program.</div>
+
Let us compile and run the program.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
| style="color:#000000;" | Click on terminal> new terminal
+
|| 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>
+
|| In the menu bar, click on '''terminal''' and select '''New Terminal.'''
  
Make sure that we are inside the cargo project .i.e '''helloworld'''
+
Make sure that we are inside the cargo project that is, '''helloworld'''
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
| style="color:#000000;" | '''> cargo build'''
+
|| '''> 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>
+
|| In the terminal. type '''cargo build '''to compile the Cargo project.
  
<div style="color:#000000;">When successfully compiled, we see a finished message.</div>
+
When successfully compiled, we see a finished message.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
| style="color:#000000;" | '''>cargo run'''
+
|| '''>cargo run'''
|| <div style="color:#000000;">As the project is compiled successfully, it’s time to run the project.</div>
+
|| As the project is compiled successfully, it’s time to run the project.
  
<span style="color:#000000;">Then type </span><span style="color:#000000;">'''cargo run'''</span>
+
Then type '''cargo run'''
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
| style="color:#000000;" | '''Point to the output'''
+
|| '''Point to the output'''
| style="color:#000000;" | Now we see '''Hello world!''' printed in the terminal.
+
|| Now we see '''Hello world!''' printed in the terminal.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| <div style="color:#000000;">'''Type '''</div>
+
|| '''Type '''
  
<div style="color:#000000;">'''Pritnln(“Welcome to Rust Spoken Tutorial”);'''</div>
+
'''Pritnln(“Welcome to Rust Spoken Tutorial”);'''
<div style="color:#000000;">'''Press Ctrl+s'''</div>
+
'''Press Ctrl+S'''
|| <div style="color:#000000;">Let us add one more print statement in the program.</div>
+
|| 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.
  
<span style="color:#000000;">Press </span>c<span style="color:#000000;">trl+s to save the file.</span>
+
Press Ctrl+ S to save the file.
  
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
| style="color:#000000;" | '''> cargo run'''
+
|| '''> cargo run'''
|| <div style="color:#000000;"></div>
+
|| In the terminal, type '''cargo run'''
  
<span style="color:#000000;">In the terminal, type</span><span style="color:#252525;"> </span><span style="color:#252525;">'''cargo run'''</span>
+
We can see both the text messages as output.
 
+
|-
<span style="color:#000000;">We can see both the text </span>messages<span style="color:#000000;"> as output.</span>
+
||  
|- style="border:1pt solid #252525;padding:0cm;"
+
| style="color:#000000;" |  
+
 
|| After switching back, I directly did a cargo run without compiling the project again.
 
|| 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;"
+
|-
| style="color:#000000;" | '''Click on cargo.toml'''
+
|| '''Click on 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>
+
|| In the left panel, open the file '''Cargo.toml.'''
  
<span style="background-color:#ffffff;color:#000000;">We </span><span style="background-color:#ffffff;color:#000000;">can </span><span style="background-color:#ffffff;color:#000000;">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>
+
We can see two sections namely '''package''' and '''dependencies.'''
  
<div style="color:#000000;">This is where we can write all the project related information like name, version, authors, edition.</div>
+
This is where we can write all the project related information like name, version, authors, edition.
  
<div style="color:#000000;">We can even mention dependencies which the project depends upon.</div>
+
We can even mention dependencies which the project depends upon.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-
|| <div style="color:#000000;">Show Slide:</div>
+
|| '''Show Slide: '''
  
<div style="color:#000000;">'''Summary'''</div>
+
'''Summary'''
|| <div style="color:#000000;">This brings us to the end of this tutorial.</div>
+
|| This brings us to the end of this tutorial.
  
<div style="color:#000000;">Let us summarize. </div>
+
Let us summarize.  
  
<div style="color:#000000;">In this tutorial, we have learnt to</div>
+
In this tutorial, we have learnt to
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Create a cargo project</div>
+
* Create a cargo project
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Write a Hello world rust program</div>
+
* Write a Hello world rust program
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Compile and Run the program</div>
+
* Compile and Run the program
  
<div style="color:#000000;"></div>
+
|-
|- style="border:1pt solid #252525;padding:0cm;"
+
|| '''Show Slide: '''
|| Slide:
+
  
Assignment
+
'''Assignment'''
  
 
|| As an assignment,
 
|| As an assignment,
* <div style="margin-left:1.27cm;margin-right:0cm;">Create a cargo project named''' assignment'''</div>
+
* Create a cargo project named''' assignment'''
* <div style="margin-left:1.27cm;margin-right:0cm;">Print - “ Welcome to Rust Assignment”</div>
+
* Print - “ Welcome to Rust Assignment”
* <div style="margin-left:1.27cm;margin-right:0cm;">Compile and execute the project</div>
+
* Compile and execute the project
* <div style="margin-left:1.27cm;margin-right:0cm;">Observe the output in the Terminal</div>
+
* Observe the output in the Terminal
  
|- 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>
+
|| '''Show Slide: '''
  
<div style="color:#000000;">'''About Spoken Tutorial Project'''</div>
+
'''About Spoken Tutorial Project'''
|| <div style="color:#000000;">The video at the following link summarizes the Spoken Tutorial Project.</div>
+
|| The video at the following link summarizes the Spoken Tutorial Project.
  
<div style="color:#000000;">Please download and watch it.</div>
+
Please download and watch it.
|- 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>
+
|| '''Show Slide: '''
  
<div style="color:#000000;">'''Spoken Tutorial Workshops'''</div>
+
'''Spoken Tutorial Workshops'''
|| <span style="color:#000000;">The </span><span style="color:#000000;">'''Spoken Tutorial Project'''</span><span style="color:#000000;"> team conducts </span><span style="color:#000000;">workshops and gives certificates.</span>
+
|| The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.
  
<div style="color:#000000;">For more details, please write to us.</div>
+
For more details, please write to us.
 
|-
 
|-
| style="border:0.75pt solid #808080;padding-top:0.176cm;padding-bottom:0.176cm;padding-left:0.134cm;padding-right:0.176cm;color:#000000;" | '''Slide : Forum for specific questions'''
+
|| '''Show Slide: '''
| style="border-top:1pt solid #252525;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;" | <div style="color:#000000;">Please post your timed queries in this forum.</div>
+
 
 +
'''Forum for specific questions'''
 +
|| Please post your timed queries in this forum.
 +
 
 +
|-
 +
||  '''Show Slide: '''
  
|- style="border:1pt solid #252525;padding-top:0.176cm;padding-bottom:0.176cm;padding-left:0.123cm;padding-right:0.176cm;"
+
'''Acknowledgement'''
|| <div style="color:#000000;">Show Slide: </div>
+
|| The''' Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''.
 +
|-  
 +
|| '''Show Slide: '''
  
<div style="color:#000000;">'''Acknowledgement'''</div>
+
'''Acknowledgement'''
|| <span style="color:#000000;">The</span><span style="color:#000000;">''' Spoken Tutorial'''</span><span style="color:#000000;"> Project was established by the </span><span style="color:#000000;">'''Ministry of Education, Government of India'''</span><span style="color:#000000;">.</span>
+
|| We would like to thank '''Vishal Pokuri from VIT Vellore '''for content contribution.
|- 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>
+
  
<div style="color:#000000;">'''Acknowledgement'''</div>
+
|| '''Show Slide: '''
|| <span style="color:#000000;">We would like to thank </span><span style="color:#000000;">'''Vishal Pokuri from VIT Vellore '''</span><span style="color:#000000;">for content contribution.</span>
+
|- 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>
+
  
<div style="color:#000000;">'''Thank you'''</div>
+
'''Thank you'''
|| <span style="color:#000000;">This tutorial is contributed by </span><span style="color:#000000;">'''Nirmala Venkat'''</span><span style="color:#000000;"> and </span><span style="color:#000000;">'''Ketki Bhamble'''</span><span style="color:#000000;"> from the spoken tutorial team.</span>
+
|| This tutorial is contributed by '''Nirmala Venkat''' and '''Ketki Bhamble''' from the spoken tutorial team.
  
<div style="color:#000000;">Thank you for joining.</div>
+
Thank you for joining.
 
|-
 
|-
 
|}
 
|}

Revision as of 13:39, 26 March 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
  • Create a cargo project
  • Write a Hello world rust program
  • Compile and Run the cargo project
Show Slide:

System Requirements

This tutorial is recorded using
  • Ubuntu Linux OS version 22.04
  • Rust version 1.80.0
  • Visual studio code version 1.19.0
Show Slide:

Prerequisites

To follow this tutorial,
  • You must have basic knowledge of any programming language
  • You should also have Rust installed on your system.
  • If not, go through the relevant tutorials on this website.
Show Slide:

About Cargo

  • Cargo is a Rust build system and package manager
  • Cargo handles the compilation process and automates the building of your project.
  • Cargo allows you to add and manage external libraries to your project
  • In the Cargo.toml file, you can list your dependencies.
  • Complex Rust programs need these dependencies to develop Rust projects
Show Slide:

Cargo commands

Let’s begin understanding the commands first.
  • To create a Cargo project use cargo new project name
  • To compile, use cargo build inside the created project.
  • To run, use cargo run inside the project


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 that is, 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

Pritnln(“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 can 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.

In this tutorial, we have learnt to

  • Create a cargo project
  • Write a Hello world rust program
  • Compile and Run the program
Show Slide:

Assignment

As an assignment,
  • Create a cargo project named assignment
  • Print - “ Welcome to Rust Assignment”
  • Compile and execute the project
  • Observe the output in the Terminal
Show Slide:

About Spoken Tutorial Project

The video at the following link summarizes the Spoken Tutorial Project.

Please download and watch it.

Show Slide:

Spoken Tutorial Workshops

The Spoken Tutorial Project team conducts workshops and gives certificates.

For more details, please write to us.

Show Slide:

Forum for specific questions

Please post your timed queries in this forum.
Show Slide:

Acknowledgement

The Spoken Tutorial Project was established by the Ministry of Education, Government of India.
Show Slide:

Acknowledgement

We would like to thank Vishal Pokuri from VIT Vellore for content contribution.
Show Slide:

Thank you

This tutorial is contributed by Nirmala Venkat and Ketki Bhamble from the spoken tutorial team.

Thank you for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat