Expand description
Provides OneBased* unsigned int types, which wraps several integers as 1-based index.
Example:
// constructs from 1-based.
let v = OneBasedU32::from_one_based(1).unwrap();
assert_eq!(v.as_zero_based(), 0);
// constructs from 0-based.
let v = OneBasedU64::from_zero_based(0).unwrap();
assert_eq!(v.as_one_based(), NonZeroU64::new(1).unwrap());
// fails to construct from zero as one-based.
let v: Option<OneBasedU32> = OneBasedU32::from_one_based(0);
assert_eq!(v, None);
// fails to construct from max as zero-based.
let v: Option<OneBasedU32> = OneBasedU32::from_zero_based(u32::MAX);
assert_eq!(v, None);
// string format uses 1-based.
let v: OneBasedU32 = "5".parse().unwrap();
assert_eq!(v.as_zero_based(), 4);
assert_eq!(v.to_string(), "5");Structsยง
- OneBased
U8 - Represents 1-based index of
u8. - OneBased
U16 - Represents 1-based index of
u16. - OneBased
U32 - Represents 1-based index of
u32. - OneBased
U64 - Represents 1-based index of
u64. - OneBased
U128 - Represents 1-based index of
u128. - OneBased
Usize - Represents 1-based index of
usize.