Rust learning: lessons, notes, and exercise crates
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/target
|
||||
Generated
+7
@@ -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"
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "learn_enum"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user