-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum.rs
34 lines (29 loc) · 836 Bytes
/
enum.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#![allow(unused)]
#[derive(Debug, PartialEq)]
enum Color {
Red,
Green,
Blue,
Rgba(u8, u8, u8, f32),
Hex(String),
Hsl { h: u8, s: u8, l: u8 },
}
fn main() {
let color = Color::Blue;
let color = Color::Rgba(100, 200, 0, 0.4);
let color = Color::Hex(String::from("ffffff"));
let color = Color::Hsl { h: 1, s: 2, l: 0 };
// Debug
println!("{:?}", color);
// PartialEq
println!("blue == red ? {}", Color::Blue == Color::Red);
println!("green == green ? {}", Color::Green == Color::Green);
// Option<T> = Some(T) | None
let x: Option<i32> = None;
let x: Option<i32> = Some(-1);
println!("{:?}", x);
// Result<T, E> = Ok(T) | Error(E)
let res: Result<i32, &str> = Err("error 💀");
let res: Result<i32, &str> = Ok(100);
println!("{:?}", res);
}