Skip to content

Instantly share code, notes, and snippets.

@AlexCouch
Created April 9, 2020 02:44
Show Gist options
  • Save AlexCouch/8c09baa013b7e26ed5b6b4ad9302fbd8 to your computer and use it in GitHub Desktop.
Save AlexCouch/8c09baa013b7e26ed5b6b4ad9302fbd8 to your computer and use it in GitHub Desktop.
const ANIMAL: u8 = 1 << 0;
const TOY: u8 = 1 << 1;
const PET: u8 = 1 << 2;
struct Dog<'d>{
abstraction: u8,
name: &'d str
}
fn main() {
let petdog = Dog{
abstraction: ANIMAL | PET,
name: "bust"
};
let toydog = Dog{
abstraction: ANIMAL | TOY,
name: "Forrest"
};
if petdog.abstraction & (ANIMAL) == ANIMAL{
println!("Pet dog is an animal")
}
if petdog.abstraction & (PET) == PET{
println!("Pet dog is an pet")
}
if toydog.abstraction & (ANIMAL) == ANIMAL{
println!("Toy dog is an animal")
}
if toydog.abstraction & (TOY)== TOY{
println!("Toy dog is an toy")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment