Difference between revisions of "Rust/C2/Printing-Hello-World-using-Cargo/English"
(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...") |
Nancyvarkey (Talk | contribs) |
||
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: | + | || 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 | + | * 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''' | + | || 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''' | ||
− | || | + | || On the '''EXPLORER''' section, expand the '''project''' folder “'''SAMPLE_HELLO_WORLD'''” by clicking on it. |
|- | |- | ||
Line 172: | Line 160: | ||
− | By default, when you create | + | 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 | + | || 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 | + | || 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 | + | || 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
|
|
Slide: Title | Welcome to the spoken tutorial on Printing Hello World using Cargo. |
Slide:
Learning Objectives |
In this tutorial we will learn:
|
Slide: System Specifications | This tutorial is recorded using:
However you may use any other editor of your choice. |
Slide : Pre-requisites |
|
Slide: Why Cargo? |
|
Slide: What does Cargo do? |
|
Slide: Cargo Commands | Let’s begin understanding the commands first.
|
Press Ctrl+Alt+T keys | Open the terminal by pressing Ctrl, Alt and T keys simultaneously on the keyboard.
|
Only Narration | Here onwards, please remember to press the Enter key after typing each command. |
[Terminal] Type:
[Enter] |
Using cd command go to the Rust practice folder which we created earlier. |
[Terminal] Type:
|
Now let us create a Cargo project named sample_hello_word
|
[Terminal] Highlight:
|
A binary cargo application has been created.
|
Open Visual Studio Code editor. | You may use any editor of your choice.
|
[Editor]
Welcome Page -> Open Folder -> sample_hello_world |
Open the created project by clicking on the Open folder link in the Welcome page.
|
[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
|
Click on the src folder to expand it.
|
[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.
|
[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:
[Enter] |
So the Cargo project is created now.
|
[Terminal] Type:
|
Now type the command to build the Cargo project. |
[Terminal] Highlight:
|
When successfully compiled, we see a finished message. |
Only narration | If we encounter any error, it means we have not installed Cargo properly.
|
[Terminal] Type:
|
As the project is compiled successfully, it’s time to run the project.
|
[Terminal] Highlight:
|
Now we see Hello world! printed in the terminal. |
Only narration | With this we have come to the end of this tutorial.
|
Slide: Summary | In this tutorial, we have learnt how to create, compile and execute a Cargo project. |
Slide: Assignment | As an assignment,
|
Slide: About Spoken Tutorial Project |
|
Slide: Spoken tutorial workshops |
|
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 |