Compare commits
2 Commits
2aab31bc69
...
f28d70b9b8
Author | SHA1 | Date | |
---|---|---|---|
f28d70b9b8 | |||
e6bc4ef483 |
@ -1,8 +1,11 @@
|
||||
fn main() {
|
||||
let x = plus_one(5);
|
||||
print_labeled_measurement(37, 'h');
|
||||
}
|
||||
|
||||
fn another_function(x: i32) {
|
||||
println!("The value of x is: {x}");
|
||||
}
|
||||
fn plus_one(x: i32) -> i32 {
|
||||
x + 1
|
||||
|
||||
fn print_labeled_measurement(value: i32, unit_label: char) {
|
||||
println!("The measurement is: {value}{unit_label}");
|
||||
}
|
||||
|
7
old_functions/Cargo.lock
generated
Normal file
7
old_functions/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "functions"
|
||||
version = "0.1.0"
|
8
old_functions/Cargo.toml
Normal file
8
old_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]
|
8
old_functions/src/main.rs
Normal file
8
old_functions/src/main.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
let x = plus_one(5);
|
||||
|
||||
println!("The value of x is: {x}");
|
||||
}
|
||||
fn plus_one(x: i32) -> i32 {
|
||||
x + 1
|
||||
}
|
7
old_variables/Cargo.lock
generated
Normal file
7
old_variables/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
8
old_variables/Cargo.toml
Normal file
8
old_variables/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
27
old_variables/src/main.rs
Normal file
27
old_variables/src/main.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
|
||||
println!("Please enter an array index.");
|
||||
|
||||
let mut index = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut index)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let index: usize = match {index.trim().parse()} {
|
||||
Ok(x) => x,
|
||||
Err(_) => {println!("expected an index, got \"{:}\". assuming 0", index.trim()); 0},
|
||||
};
|
||||
|
||||
println!("got value {index}");
|
||||
|
||||
let element = a[index];
|
||||
|
||||
/* this is a
|
||||
* multiline
|
||||
* comment */
|
||||
println!("The value of the element at index {index} is: {element}");
|
||||
}
|
@ -1,27 +1,11 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
let x = 5;
|
||||
let x = x + 1;
|
||||
|
||||
println!("Please enter an array index.");
|
||||
{
|
||||
let x=x*2;
|
||||
println!("The value of x in the inner scope is: {x}");
|
||||
}
|
||||
|
||||
let mut index = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut index)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let index: usize = match {index.trim().parse()} {
|
||||
Ok(x) => x,
|
||||
Err(_) => {println!("expected an index, got \"{:}\". assuming 0", index.trim()); 0},
|
||||
};
|
||||
|
||||
println!("got value {index}");
|
||||
|
||||
let element = a[index];
|
||||
|
||||
/* this is a
|
||||
* multiline
|
||||
* comment */
|
||||
println!("The value of the element at index {index} is: {element}");
|
||||
println!("The value of x is: {x}");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user