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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(One intermediate revision by one other user not shown)
Line 4: Line 4:
 
|| '''Narration'''
 
|| '''Narration'''
 
|-
 
|-
|| '''Show Slide: '''
+
|| Show Slide:  
  
 
'''Title Slide'''
 
'''Title Slide'''
  
|| Welcome to the Spoken tutorial on '''Hello World using Cargo'''.
+
|| Welcome to the Spoken tutorial on '''Hello World using Cargo.'''
|-
+
|-  
|| '''Show Slide: '''
+
|| Show Slide:  
  
 
'''Learning Objectives'''
 
'''Learning Objectives'''
Line 18: Line 18:
 
* Compile and Run the cargo project
 
* Compile and Run the cargo project
  
|-
+
|-  
|| '''Show Slide: '''
+
|| Show Slide:
  
 
'''System Requirements'''
 
'''System Requirements'''
|| This tutorial is recorded using,
+
|| This tutorial is recorded using
 
* Ubuntu Linux OS version 22.04
 
* Ubuntu Linux OS version 22.04
 
* Rust version 1.80.0  
 
* Rust version 1.80.0  
 
* Visual studio code version 1.19.0
 
* Visual studio code version 1.19.0
  
|-
+
|-  
|| '''Show Slide: '''
+
|| Show slide:
  
'''Prerequisites'''
+
Prerequisite
 
|| To follow this tutorial,
 
|| To follow this tutorial,
 
* You must have basic knowledge of any programming language
 
* You must have basic knowledge of any programming language
 
* You should also have '''Rust '''installed on your system.
 
* You should also have '''Rust '''installed on your system.
* If not, go through the relevant tutorials on this website.
 
  
|-
+
|-  
|| '''Show Slide: '''
+
|| '''Slide: '''
  
 
'''About Cargo'''
 
'''About Cargo'''
Line 44: Line 43:
 
* '''Cargo '''is a '''Rust build system''' and '''package manager'''
 
* '''Cargo '''is a '''Rust build system''' and '''package manager'''
 
* Cargo handles the compilation process and automates the building of your project.
 
* Cargo handles the compilation process and automates the building of your project.
* Cargo allows you to add and manage external libraries to your project
+
* Cargo allows you at add and manage external libraries
* In the '''Cargo.toml '''file, you can list your dependencies.
+
* In the Cargo.toml''' '''file, you can list your dependencies.
* Complex '''Rust '''programs need these '''dependencies''' to develop '''Rust projects'''
+
* Complex '''Rust '''programs need these '''dependencies''' to develop '''Rust projects'''.
|-
+
|| '''Show Slide:'''
+
  
'''Cargo commands'''
+
|-
|| Let’s begin understanding the commands first.
+
|| Open Visual code editor
* 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.'''
 
|| Let us open the '''Visual Studio Code editor.'''
|-
+
|-  
|| Click on '''terminal''' and select '''New Terminal.'''
+
|| click on '''terminal''' and select '''New Terminal.'''
|| In the menu bar, 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.
 
We can see a terminal window at the bottom.
|-
+
|-  
 
|| Create direcotry '''MyRustProject'''
 
|| Create direcotry '''MyRustProject'''
  
Line 71: Line 63:
 
>cd Desktop/MyRustProject
 
>cd Desktop/MyRustProject
  
|| Let us create a directory '''MyRustProject''' on the '''Desktop'''.
+
|| Let us create a directory '''MyRustProject''' on the Desktop.
  
 
In the terminal, type as shown to create a directory '''MyRustProject'''.
 
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.
|-
+
|-  
 
|| Type
 
|| Type
  
 
>'''cargo new helloworld'''
 
>'''cargo new helloworld'''
|| Type the command '''cargo new helloworld'''.
+
|| Type the command '''cargo new helloworld'''
  
A binary '''cargo''' application has been created.
+
A binary cargo application has been created.
|-
+
|-  
 
|| Click File>> Open folder
 
|| Click File>> Open folder
  
 
Select hello folder under MyRustPRoject
 
Select hello folder under MyRustPRoject
 
+
|| Open the created project by clicking on the '''File''' menu in the menu bar and then '''Open folder.'''
|| 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'''.
 
Go to '''Desktop''' and then select '''MyRustProject'''.
Line 94: Line 85:
 
Locate the '''helloworld''' folder.
 
Locate the '''helloworld''' folder.
  
Then click on the '''Open''' button at the top right corner.
+
Then click on the '''open''' button at the top right corner.
|-
+
|-  
 
|| '''Click src folder> main.rs'''
 
|| '''Click src folder> main.rs'''
|| In the left panel, under the '''EXPLORER''' section, expand the project '''HELLO''' by clicking on it.
+
|| 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 the '''src''' folder, and you can see that a file called '''main.rs''' is created.
Line 103: Line 94:
 
Click on it to open the file.
 
Click on it to open the file.
  
All the code has to be run using this particular file '''main.rs'''.
+
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.
 
By default, we can see a hello world program on the right panel.
|-
+
|-  
 
||  
 
||  
|| Let us see the '''Rust''' program structure.
+
|| Let us see the Rust program structure.
|-
+
|-  
 
|| '''Highlight according to narration.'''
 
|| '''Highlight according to narration.'''
  
Line 124: Line 115:
 
The '''semicolon `;`''' at the end indicates the end of the command.
 
The '''semicolon `;`''' at the end indicates the end of the command.
  
Save the file by pressing '''Ctrl + S'''.
+
Save the file by pressing '''Ctrl + S.'''
  
 
Let us compile and run the program.
 
Let us compile and run the program.
|-
+
|-  
 
|| Click on terminal> new terminal
 
|| Click on terminal> new terminal
|| In the menu bar, click on '''terminal''' and select '''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'''
+
Make sure that we are inside the cargo project that is '''helloworld'''
|-
+
|-  
 
|| '''> cargo build'''
 
|| '''> cargo build'''
|| In the terminal. type '''cargo build ''' to compile the '''Cargo''' project.
+
|| In the terminal, type '''cargo build '''to compile the Cargo project.
  
 
When successfully compiled, we see a finished message.
 
When successfully compiled, we see a finished message.
|-
+
|-  
 
|| '''>cargo run'''
 
|| '''>cargo run'''
 
|| As the project is compiled successfully, it’s time to run the project.
 
|| As the project is compiled successfully, it’s time to run the project.
  
Then type '''cargo run'''.
+
Then type '''cargo run'''
|-
+
|-  
 
|| '''Point to the output'''
 
|| '''Point to the output'''
|| Now we see '''Hello world!''' printed in the terminal.
+
|| Now we see Hello world! printed in the terminal.
|-
+
|-  
 
|| '''Type '''
 
|| '''Type '''
  
'''Pritnln(“Welcome to Rust Spoken Tutorial”);'''
+
'''Println!(“Welcome to Rust Spoken Tutorial”);'''
'''Press Ctrl+S'''
+
 
 +
'''Press Ctrl+s'''
 
|| Let us add one more print statement in the program.
 
|| 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 Ctrl + S to save the file.
+
Press Ctrl+ S to save the file.
  
|-
+
|-
 
|| '''> cargo run'''
 
|| '''> cargo run'''
|| In the terminal, type '''cargo run'''
+
|| In the terminal, type '''cargo run'''
  
 
We can see both the text messages as output.
 
We can see both the text messages as output.
|-
+
|-  
 
||  
 
||  
|| 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.
|-
+
|-  
 
|| '''Click on cargo.toml'''
 
|| '''Click on cargo.toml'''
 
|| In the left panel, open the file '''Cargo.toml.'''
 
|| In the left panel, open the file '''Cargo.toml.'''
  
We can see two sections namely '''package''' and '''dependencies'''.
+
We see two sections namely '''package''' and '''dependencies.'''
  
 
This is where we can write all the project related information like name, version, authors, edition.
 
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.
 
We can even mention dependencies which the project depends upon.
|-
+
|-  
|| '''Show Slide: '''
+
|| Show Slide:
  
 
'''Summary'''
 
'''Summary'''
Line 186: Line 178:
  
 
Let us summarize.  
 
Let us summarize.  
 +
|-
 +
|| Slide:
  
In this tutorial, we have learnt to
+
Assignment
* Create a cargo project
+
* Write a Hello world '''rust''' program
+
* Compile and Run the program
+
 
+
|-
+
||  '''Show Slide: '''
+
 
+
'''Assignment'''
+
  
 
|| As an assignment,
 
|| As an assignment,
Line 204: Line 190:
  
 
|-  
 
|-  
|| '''Show Slide: '''
+
|| 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 the content contribution.
+
|-
+
 
+
||  '''Show Slide: '''
+
  
 
'''Thank you'''
 
'''Thank you'''
|| This tutorial is contributed by '''Nirmala Venkat''' and '''Ketki Bhamble''' from the spoken tutorial team.
+
|| Thank you for joining.
 
+
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