Compare commits

..

No commits in common. "f28d70b9b85f84d0d841b6b04d44a92b5c7009ea" and "2aab31bc69c07fc43bae731da0c46c9b8d732996" have entirely different histories.

8 changed files with 26 additions and 78 deletions

View File

@ -1,11 +1,8 @@
fn main() { fn main() {
print_labeled_measurement(37, 'h'); let x = plus_one(5);
}
fn another_function(x: i32) {
println!("The value of x is: {x}"); println!("The value of x is: {x}");
} }
fn plus_one(x: i32) -> i32 {
fn print_labeled_measurement(value: i32, unit_label: char) { x + 1
println!("The measurement is: {value}{unit_label}");
} }

View File

@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "functions"
version = "0.1.0"

View File

@ -1,8 +0,0 @@
[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]

View File

@ -1,8 +0,0 @@
fn main() {
let x = plus_one(5);
println!("The value of x is: {x}");
}
fn plus_one(x: i32) -> i32 {
x + 1
}

View File

@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "variables"
version = "0.1.0"

View File

@ -1,8 +0,0 @@
[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]

View File

@ -1,27 +0,0 @@
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}");
}

View File

@ -1,11 +1,27 @@
use std::io;
fn main() { fn main() {
let x = 5; let a = [1, 2, 3, 4, 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}");
}
println!("The value of x 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}");
} }