Created
September 25, 2018 03:29
-
-
Save rust-play/380b397be10efc204804d9094d04c97a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code)] | |
use Nop::*; | |
enum Nop { | |
Fox(i32, i32), | |
Pony(i32, i32), | |
} | |
struct Miv { | |
small: i32, | |
pub cat: i32, | |
} | |
fn main() { | |
let nop = Nop::Fox(12, 433); | |
let miv = Miv { | |
small: 44, | |
cat: 643, | |
}; | |
// Nop enum takes a little bit more funny business to access: | |
let noprating: i32 = if let Fox(foxnum, _) = nop { foxnum } else { 0 }; | |
// Miv struct is a lot easier: | |
let mivrating = miv.cat; | |
println!("Nop has a fox rating of... {}.", noprating); | |
println!("Miv has a cat rating of... {}.", mivrating); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment