Rust learning: lessons, notes, and exercise crates

This commit is contained in:
2026-09-06 23:59:08 +07:00
commit 6ddf41aa81
119 changed files with 10873 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "learn_enum"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "learn_enum"
version = "0.1.0"
edition = "2024"
[dependencies]
+46
View File
@@ -0,0 +1,46 @@
enum IpVer {
V4(String),
V6(String),
}
enum Coin {
Penny,
Nickel,
Dime,
Quarter(String),
}
fn main() {
println!("Hello, world!");
let home = IpVer::V4("192.14.1.1".into());
let loopback = IpVer::V6("::1".into());
value_in_cents(Coin::Quarter("alaska".to_string()));
let config_max = Some(3u8);
match config_max {
Some(max) => println!("the maximum is configure to be {max}"),
_ => (),
}
if let Some(max) = config_max
&& max < 4
{
println!("Maximum is {max}");
}
}
fn value_in_cents(coin: Coin) -> u8 {
match coin {
Coin::Penny => {
println!("Lucky Penny");
1
}
Coin::Nickel => 5,
Coin::Dime => 10,
Coin::Quarter(s) => {
println!("from state {s}");
25
}
}
}