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

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "Title of the script: Printing Hello, World using Cargo Author: Jayesh Katta Ramalingaiah Domain Reviewer: Novice Reviewer: Keywords: Rust, cargo, package manager, functi...")
 
Line 26: Line 26:
  
 
* How to create a '''Cargo project''' and  
 
* How to create a '''Cargo project''' and  
* Execute it.
+
* '''Execute''' it.
 
+
 
+
  
 
|-
 
|-
Line 45: Line 43:
 
* To practice this tutorial, you should be familiar with basic '''Linux commands.'''
 
* To practice this tutorial, you should be familiar with basic '''Linux commands.'''
 
* If not, please go through the prerequisite tutorials on this website.
 
* If not, please go through the prerequisite tutorials on this website.
 
 
  
 
|-
 
|-
Line 53: Line 49:
 
* '''Cargo '''is a '''Rust build system''' and '''package manager'''
 
* '''Cargo '''is a '''Rust build system''' and '''package manager'''
 
* '''Rustaceans''' use '''cargo '''to manage their '''projects''' as it makes the '''developer'''’s life easier.
 
* '''Rustaceans''' use '''cargo '''to manage their '''projects''' as it makes the '''developer'''’s life easier.
 
 
  
 
|-
 
|-
Line 62: Line 56:
 
* '''Downloading '''and managing '''libraries '''that our '''code '''depends on.
 
* '''Downloading '''and managing '''libraries '''that our '''code '''depends on.
 
* Complex '''Rust '''programs need these '''dependencies''' to develop '''Rust projects'''.
 
* Complex '''Rust '''programs need these '''dependencies''' to develop '''Rust projects'''.
 
 
  
 
|-
 
|-
|| Slide: Create, Compile and Execute the '''Cargo '''Project
+
|| Slide: '''Cargo Commands'''  
 
|| Let’s begin understanding the '''commands '''first.
 
|| Let’s begin understanding the '''commands '''first.
  
  
* To create a '''Cargo project''' use '''cargo new project_name'''
+
* To create a '''Cargo project''' use '''cargo new project name'''
 
* To '''compile''', use '''cargo build''' inside the created '''project'''.
 
* To '''compile''', use '''cargo build''' inside the created '''project'''.
 
* To '''run''', use '''cargo run '''inside the '''project'''.
 
* To '''run''', use '''cargo run '''inside the '''project'''.
 
 
  
 
|-
 
|-
 
|| Press '''Ctrl+Alt+T '''keys
 
|| Press '''Ctrl+Alt+T '''keys
|| Open the '''terminal''' by pressing '''Ctrl,Alt''' and '''T''' keys simultaneously on the keyboard.
+
|| Open the '''terminal''' by pressing '''Ctrl, Alt''' and '''T''' keys simultaneously on the keyboard.
  
  
Line 112: Line 102:
 
Created binary (application) `sample_hello_world` package
 
Created binary (application) `sample_hello_world` package
 
|| A '''binary cargo application''' has been created.
 
|| A '''binary cargo application''' has been created.
 
 
  
  
Line 131: Line 119:
  
 
sample_hello_world
 
sample_hello_world
|| Open the created '''project''' by clicking on the '''Open folder''' link in the '''Welcome page'''
+
|| Open the created '''project''' by clicking on the '''Open folder link''' in the '''Welcome page'''.
  
  
Line 143: Line 131:
  
 
Click on '''SAMPLE_HELLO_WORLD'''
 
Click on '''SAMPLE_HELLO_WORLD'''
|| Under the '''EXPLORER''' section, expand the '''project''' folder “'''SAMPLE_HELLO_WORLD'''” by clicking on it.
+
|| On the '''EXPLORER''' section, expand the '''project''' folder “'''SAMPLE_HELLO_WORLD'''” by clicking on it.
  
 
|-
 
|-
Line 172: Line 160:
  
  
By default, when you create the '''cargo project''', it creates the '''main.rs''' file inside the '''src''' folder.  
+
By default, when you create a '''cargo project''', it creates the '''main.rs''' file inside the '''src''' folder.  
  
  
Line 179: Line 167:
 
|-
 
|-
 
|| <nowiki>[Editor] </nowiki>Click on '''Cargo.toml'''
 
|| <nowiki>[Editor] </nowiki>Click on '''Cargo.toml'''
|| Open the file '''Cargo.toml''' from the '''project''' folder by clicking on it
+
|| Open the file '''Cargo.toml''' from the '''project''' folder by clicking on it.
  
 
|-
 
|-
Line 186: Line 174:
 
Highlight the code
 
Highlight the code
 
|| We see two sections namely '''package''' and '''dependencies.'''
 
|| We see two sections namely '''package''' and '''dependencies.'''
 
 
  
  
Line 200: Line 186:
  
 
Highlight the '''dependencies''' section
 
Highlight the '''dependencies''' section
|| We can even mention the '''dependencies''' which the '''project''' depends upon.
+
|| We can even mention '''dependencies''' which the '''project''' depends upon.
  
 
|-
 
|-
Line 223: Line 209:
  
 
'''cargo build '''<nowiki>[Enter]</nowiki>
 
'''cargo build '''<nowiki>[Enter]</nowiki>
|| Now type the following '''command''' to build the '''Cargo project.'''
+
|| Now type the '''command''' to '''build''' the '''Cargo project.'''
  
 
|-
 
|-
Line 237: Line 223:
  
  
Please revisit the installation tutorial and install '''Cargo''' properly before continuing.
+
Please revisit the '''installation''' tutorial and install '''Cargo''' properly before continuing.
  
 
|-
 
|-
Line 254: Line 240:
  
 
'''Hello, world!'''
 
'''Hello, world!'''
|| Now we see '''Hello world''' printed in the '''terminal'''.
+
|| Now we see '''Hello world!''' printed in the '''terminal'''.
  
 
|-
 
|-
Line 264: Line 250:
  
 
|-
 
|-
|| Slide''': '''Summary''' '''
+
|| Slide: '''Summary'''  
 
|| In this tutorial, we have learnt how to '''create, compile '''and''' execute''' a '''Cargo project'''.
 
|| In this tutorial, we have learnt how to '''create, compile '''and''' execute''' a '''Cargo project'''.
  
Line 275: Line 261:
 
* '''Compile '''and '''execute '''the '''project'''.
 
* '''Compile '''and '''execute '''the '''project'''.
 
* Observe the output in the '''Terminal'''
 
* Observe the output in the '''Terminal'''
 
 
  
 
|-
 
|-
Line 282: Line 266:
 
||  
 
||  
 
* The video at the following link summarises the Spoken Tutorial project.
 
* The video at the following link summarises the Spoken Tutorial project.
* Please download and watch it
+
* Please download and watch it.
 
+
 
+
  
 
|-
 
|-
Line 291: Line 273:
 
* We conduct workshops using spoken tutorials and give certificates.
 
* We conduct workshops using spoken tutorials and give certificates.
 
* For more details, please write to us.
 
* For more details, please write to us.
 
 
  
 
|-
 
|-

Revision as of 13:44, 21 January 2021

Title of the script: Printing Hello, World using Cargo

Author: Jayesh Katta Ramalingaiah

Domain Reviewer:

Novice Reviewer:

Keywords: Rust, cargo, package manager, function, rs


Visual Cue
Narration
Slide: Title Welcome to the spoken tutorial on Printing Hello World using Cargo.
Slide:

Learning Objectives

In this tutorial we will learn:
  • How to create a Cargo project and
  • Execute it.
Slide: System Specifications This tutorial is recorded using:
  • Ubuntu Linux OS version 18.04
  • Rust version 1.47.0
  • Visual Studio Code version 1.45.0 (code editor)

However you may use any other editor of your choice.

Slide : Pre-requisites
  • To practice this tutorial, you should be familiar with basic Linux commands.
  • If not, please go through the prerequisite tutorials on this website.
Slide: Why Cargo?
  • Cargo is a Rust build system and package manager
  • Rustaceans use cargo to manage their projects as it makes the developer’s life easier.
Slide: What does Cargo do?
  • Cargo takes care of building our code
  • Downloading and managing libraries that our code depends on.
  • Complex Rust programs need these dependencies to develop Rust projects.
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.
Press Ctrl+Alt+T keys Open the terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard.


Ensure that you have root permissions to run the commands.

Only Narration Here onwards, please remember to press the Enter key after typing each command.
[Terminal] Type:


cd Desktop/MyRustProject

[Enter]

Using cd command go to the Rust practice folder which we created earlier.
[Terminal] Type:


cargo new sample_hello_world [Enter]

Now let us create a Cargo project named sample_hello_word


To do so, type the command as shown.

[Terminal] Highlight:


Created binary (application) `sample_hello_world` package

A binary cargo application has been created.


Open Visual Studio Code editor. You may use any editor of your choice.


I will use Visual Studio Code editor for this demonstration.

[Editor]

Welcome Page ->

Open Folder ->

sample_hello_world

Open the created project by clicking on the Open folder link in the Welcome page.


Browse and locate the folder “sample_hello_world”.


Then click on the OK button at the top right corner.

[Editor]

Click on SAMPLE_HELLO_WORLD

On the EXPLORER section, expand the project folder “SAMPLE_HELLO_WORLD” by clicking on it.
[Editor]

For respective names - show cursor in the left side pane

We see the src folder and a Cargo.toml file created inside the project folder.
[Editor] Click on src


Point to main.rs

Click on the src folder to expand it.


We find main.rs file inside the src folder.

[Editor] Click on main.rs Open the file main.rs by clicking on it.
[Editor - main.rs]

Highlight the code

We can see the hello world program written inside.


By default, when you create a cargo project, it creates the main.rs file inside the src folder.


And a main function would be written by default.

[Editor] Click on Cargo.toml Open the file Cargo.toml from the project folder by clicking on it.
[Editor - Cargo.toml]

Highlight the code

We see two sections namely package and dependencies.


[Editor - Cargo.toml]

Highlight the package section

This is where we can write all the project related information like name, version, authors, edition.
[Editor - Cargo.toml]

Highlight the dependencies section

We can even mention dependencies which the project depends upon.
Switch to terminal Switch back to the terminal.
[Terminal] Type:


cd sample_hello_world

[Enter]

So the Cargo project is created now.


Navigate inside the cargo project sample_hello_world using the cd command.

[Terminal] Type:


cargo build [Enter]

Now type the command to build the Cargo project.
[Terminal] Highlight:


Finished

When successfully compiled, we see a finished message.
Only narration If we encounter any error, it means we have not installed Cargo properly.


Please revisit the installation tutorial and install Cargo properly before continuing.

[Terminal] Type:


cargo run [Enter]

As the project is compiled successfully, it’s time to run the project.


To run, type cargo run.

[Terminal] Highlight:


Hello, world!

Now we see Hello world! printed in the terminal.
Only narration With this we have come to the end of this tutorial.


Let’s summarize.

Slide: Summary In this tutorial, we have learnt how to create, compile and execute a Cargo project.
Slide: Assignment As an assignment,
  • Create a cargo project named rust-assignment
  • Print - ‘Welcome to Spoken Tutorials!’
  • Compile and execute the project.
  • Observe the output in the Terminal
Slide: About Spoken Tutorial Project
  • The video at the following link summarises the Spoken Tutorial project.
  • Please download and watch it.
Slide: Spoken tutorial workshops
  • We conduct workshops using spoken tutorials and give certificates.
  • For more details, please write to us.
Slide: Forum questions Pls post your timed questions in this forum
Slide: Acknowledgement Spoken Tutorial Project is funded by Ministry of Education, Government of India
Slide: Thanks This is Jayesh signing off. Thank you for joining

Contributors and Content Editors

Kr.jayesh, Nancyvarkey