rust match string
match stringthing.as_str() {
"a" => println!("0"),
"b" => println!("1"),
"c" => println!("2"),
_ => println!("something else!"),
}
rust match string
match stringthing.as_str() {
"a" => println!("0"),
"b" => println!("1"),
"c" => println!("2"),
_ => println!("something else!"),
}
rust match statement
#[derive(Debug)] // so we can inspect the state in a minute
enum UsState {
Alabama,
Alaska,
// --snip--
}
#[derive(Debug)]
enum Coin {
Penny,
Nickel,
Dime,
Quarter(UsState),
}
fn return_the_coin(coin:Coin) ->u8{
match coin{
Coin::Penny =>1,
Coin::Nickel =>10,
Coin::Dime =>15,
Coin::Quarter(state) =>{
println!("{:#?}",state);
25
}
}
}
fn main() {
let rtn=return_the_coin(Coin::Quarter(UsState::Alabama));
println!("{:#?}",rtn);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us