rustlings/exercises/enums/enums3.rs
Xander b09049b906 feat: Added exercises/enums
Added 3 new exercises for enums, enums{1-3}.rs
2019-08-25 11:29:10 -04:00

62 lines
919 B
Rust

// enums3.rs
// Try making an enum to immitate these structs
// Tuple Struct
struct FruitBasketRecipient(String);
// Classic Struct
struct FruitBasketSize {
depth: i32,
width: i32,
}
// Unit Struct
struct FruitBasketEmpty;
// Complete this definition so the file compiles
#[derive(Debug)]
enum FruitBasket {
}
fn main() {
// These do not need to be touched :) but the file will not compile if the
// elements of the enum have not been defines
let recipient = FruitBasket::Recipient(String::from("John Doe"));
println!("The fruit basket says: {:#?}", recipient);
let size = FruitBasket::Size{depth:3, width:4};
println!("The manual for the fruit basket says: {:#?}", size);
let is_empty = FruitBasket::Empty;
}
// Rust can store many different types of values in an enum, check out the
// 'Enum Values' Subsection of the Enum chapter for more info