Is bool guaranteed to be 1 byte?

Rust emits i1 to LLVM for bool and relies on whatever it produces. LLVM uses i8 (one byte) to represent i1 in memory for all the platforms supported by Rust for now. On the other hand, there’s no certainty about the future, since the Rust developers have been refusing to commit to the particular bool … Read more

How to build an Rc or Rc?

As of Rust 1.21.0 and as mandated by RFC 1845, creating an Rc<str> or Arc<str> is now possible: use std::rc::Rc; use std::sync::Arc; fn main() { let a: &str = “hello world”; let b: Rc<str> = Rc::from(a); println!(“{}”, b); // or equivalently: let b: Rc<str> = a.into(); println!(“{}”, b); // we can also do this for … Read more

Parsing a char to u32

char::to_digit(radix) does that. radix denotes the “base”, i.e. 10 for the decimal system, 16 for hex, etc.: let a = “29”; for c in a.chars() { println!(“{:?}”, c.to_digit(10)); } It returns an Option, so you need to unwrap() it, or better: expect(“that’s no number!”). You can read more about proper error handling in the appropriate … Read more