How do I convert a boolean to an integer in Rust? As in, true becomes 1, and false becomes 0.
true
false
You may use .into():
.into()
let a = true; let b: i32 = a.into(); println!("{}", b); // 1 let z: isize = false.into(); println!("{}", z); // 0
playground