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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
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
 
Prerequisite
 
|| 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.
  
|- style="border:1pt solid #252525;padding:0cm;"
+
|-  
|| <div style="color:#000000;">'''&nbsp;Slide: '''</div>
+
|| '''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 at add and manage external libraries</div>
+
* Cargo allows you at add and manage external libraries
* <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>
+
* 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;"
+
|-  
|| <div style="color:#000000;">Open Visual code editor</div>
+
|| Open Visual code editor
  
|| <span style="color:#000000;">Let us open the </span><span style="color:#000000;">'''Visual Studio Code editor.'''</span>
+
|| Let us open the '''Visual Studio Code editor.'''
|- style="border:1pt solid #252525;padding:0cm;"
+
|-  
|| <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>
+
|| click on '''terminal''' and select '''New Terminal.'''
|| <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.'''
  
<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.</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>.
+
|| 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.
 
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>
+
|| Type
  
<span style="color:#000000;">></span><span style="color:#000000;">'''cargo new hellowor</span>ld'''
+
>'''cargo new helloworld'''
|| <span style="color:#000000;">Type the command </span><span style="color:#000000;">'''cargo new hellowor</span>ld'''
+
|| Type the command '''cargo new helloworld'''
  
<div style="color:#000000;">A binary cargo application has been created.</div>
+
A binary cargo application has been created.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-  
|| <div style="color:#000000;">Click File>> Open folder</div>
+
|| Click File>> Open folder
  
<div style="color:#000000;">Select hello folder under MyRustPRoject</div>
+
Select hello folder under MyRustPRoject
|| <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>
+
|| 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;">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>
+
Go to '''Desktop''' and then select '''MyRustProject'''.
  
<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>
+
Locate the '''helloworld''' folder.
  
<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>
+
Then click on the '''open''' button at the top right corner.
|- style="border:1pt solid #252525;padding:0cm;"
+
|-  
| style="color:#000000;" | '''Click src folder> main.rs'''
+
|| '''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>
+
|| In the left panel, under the '''EXPLORER''' section, expand the project '''hello''' by clicking on it.
  
<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 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 '''
  
<span style="background-color:#ffffff;">'''Println!</span><span style="background-color:#ffffff;color:#000000;">(“Welcome to Rust Spoken Tutorial”);'''</span>
+
'''Println!(“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 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 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.  
|- style="border:1pt solid #252525;padding:0cm;"
+
|-  
 
|| Slide:
 
|| Slide:
  
Line 184: Line 184:
  
 
|| 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;">'''Thank you'''</div>
+
'''Thank you'''
|| <span style="color:#000000;">Thank you for joining.</span>
+
|| Thank you for joining.
 
|-
 
|-
 
|}
 
|}

Latest revision as of 17:43, 4 August 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:

Prerequisite

To follow this tutorial,
  • You must have basic knowledge of any programming language
  • You should also have Rust installed on your system.
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 at add and manage external libraries
  • In the Cargo.toml file, you can list your dependencies.
  • Complex Rust programs need these dependencies to develop Rust projects.
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

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,
  • Create a cargo project named assignment
  • Print - “ Welcome to Rust Assignment”
  • Compile and execute the project
  • Observe the output in the Terminal
Show Slide:

Thank you

Thank you for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat