A newtype wraps an existing value in a tuple struct to add meaning or type safety without much extra encapsulation. It suits data already represented adequately by a primitive, such as a `u32`. section 5.7
#[derive(Debug)] struct BitCount(u32); #[derive(Debug)] struct ByteCount(u32);
These tuple structs give bit counts and byte counts distinct types, even though both contain a `u32`. section 5.7
Add methods to define safe conversions: `BitCount::to_bytes` divides by eight, while `ByteCount::to_bits` multiplies by eight. The tuple field remains directly accessible as `.0`, keeping the wrapper lightweight; use newtype when that simplicity is useful. section 5.7
impl BitCount {
fn to_bytes(&self) -> ByteCount {
ByteCount(self.0 / 8) #1
}
}
impl ByteCount {
fn to_bits(&self) -> BitCount {
BitCount(self.0 * 8)
}
}
The conversion methods construct the destination wrapper around the converted value. section 5.7



