1个不稳定版本
0.1.0 | 2019年7月17日 |
---|
#67 在 #microsoft
7KB
75 行
mso-tri-state
: 无畏布尔值
那些简单真/假布尔变量的时代已经过去了。现代软件需要现代解决方案:MsoTriState
。
受微软信任。
旧、慢、古老、不安全的代码
let foo = true;
if foo {
println!("Hello, world!");
}
// Hard to read, intent unclear
let bar = 1 == 2;
match bar {
false => println!("One does not equal two"),
true => println!("One equals two"),
// Restrictive, not web-scale
}
新、快、Web级、安全的代码
extern crate mso_tri_state;
use mso_tri_state::MsoTriState;
// Clean and easy to read
let foo = MsoTriState::msoTrue;
if foo.into() {
println!("Hello, world!");
}
// Simple, effortless conversion
let bar: MsoTriState = (1 == 2).into();
match bar {
MsoTriState::msoFalse => println!("One does not equal two"),
MsoTriState::msoTrue => println!("One equals two"),
// Highly future-proof and scalable
_ => panic!(),
}
// Compatible with all major brands
let has_a_3 = MsoTriState::from(vec![1, 2, 4, 5].contains(&3));
println!("Has a 3: {}", has_a_3); // prints "Has a 3: msoFalse"