Created
April 9, 2020 02:44
-
-
Save AlexCouch/8c09baa013b7e26ed5b6b4ad9302fbd8 to your computer and use it in GitHub Desktop.
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
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