Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 25, 2018 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/380b397be10efc204804d9094d04c97a to your computer and use it in GitHub Desktop.
Save rust-play/380b397be10efc204804d9094d04c97a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![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