added function and variable lessons.
This commit is contained in:
parent
4106843d70
commit
405437686a
6 changed files with 118 additions and 0 deletions
8
the_book/functions/Cargo.toml
Normal file
8
the_book/functions/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "functions"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
16
the_book/functions/src/main.rs
Normal file
16
the_book/functions/src/main.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
fn main() {
|
||||
another_function(5);
|
||||
print_labeled_measurement(50, 'm');
|
||||
println!("The returned value is {}", plus_one(4));
|
||||
}
|
||||
|
||||
fn another_function(x: i32) {
|
||||
println!("The value of x is: {}", x);
|
||||
}
|
||||
fn print_labeled_measurement(value: i32, unit_label: char) {
|
||||
println!("The measurement is: {}{}", value, unit_label);
|
||||
}
|
||||
//adds one and returns
|
||||
fn plus_one(x:i32) -> i32 {
|
||||
x+1
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue