pub struct LineNumber(/* private fields */);Expand description
Type-safe wrapper for a value whose logical range starts at 1, for
instance the line or column numbers in a file
Internally this is represented as a NonZeroUsize, this enables some
memory optimizations
Implementations§
Source§impl OneIndexed
impl OneIndexed
Sourcepub const MAX: OneIndexed
pub const MAX: OneIndexed
The largest value that can be represented by this integer type
Sourcepub const MIN: OneIndexed
pub const MIN: OneIndexed
The smallest value that can be represented by this integer type.
pub const ONE: NonZero<usize>
Sourcepub const fn new(value: usize) -> Option<OneIndexed>
pub const fn new(value: usize) -> Option<OneIndexed>
Creates a non-zero if the given value is not zero.
Sourcepub const fn from_zero_indexed(value: usize) -> OneIndexed
pub const fn from_zero_indexed(value: usize) -> OneIndexed
Construct a new OneIndexed from a zero-indexed value
Sourcepub const fn to_zero_indexed(self) -> usize
pub const fn to_zero_indexed(self) -> usize
Return the zero-indexed primitive value for this OneIndexed
Sourcepub const fn saturating_add(self, rhs: usize) -> OneIndexed
pub const fn saturating_add(self, rhs: usize) -> OneIndexed
Saturating integer addition. Computes self + rhs, saturating at
the numeric bounds instead of overflowing.
Sourcepub const fn saturating_sub(self, rhs: usize) -> OneIndexed
pub const fn saturating_sub(self, rhs: usize) -> OneIndexed
Saturating integer subtraction. Computes self - rhs, saturating
at the numeric bounds instead of overflowing.
Sourcepub fn checked_add(self, rhs: OneIndexed) -> Option<OneIndexed>
pub fn checked_add(self, rhs: OneIndexed) -> Option<OneIndexed>
Checked addition. Returns None if overflow occurred.
Sourcepub fn checked_sub(self, rhs: OneIndexed) -> Option<OneIndexed>
pub fn checked_sub(self, rhs: OneIndexed) -> Option<OneIndexed>
Checked subtraction. Returns None if overflow occurred.
Sourcepub const fn digits(self) -> NonZero<usize>
pub const fn digits(self) -> NonZero<usize>
Calculate the number of digits in self.
This is primarily intended for computing the length of the string representation for formatted printing.
§Examples
use ruff_source_file::OneIndexed;
let one = OneIndexed::new(1).unwrap();
assert_eq!(one.digits().get(), 1);
let hundred = OneIndexed::new(100).unwrap();
assert_eq!(hundred.digits().get(), 3);
let thousand = OneIndexed::new(1000).unwrap();
assert_eq!(thousand.digits().get(), 4);Trait Implementations§
Source§impl Clone for OneIndexed
impl Clone for OneIndexed
Source§fn clone(&self) -> OneIndexed
fn clone(&self) -> OneIndexed
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OneIndexed
impl Debug for OneIndexed
Source§impl Default for OneIndexed
impl Default for OneIndexed
Source§fn default() -> OneIndexed
fn default() -> OneIndexed
Source§impl Display for OneIndexed
impl Display for OneIndexed
Source§impl FromStr for OneIndexed
impl FromStr for OneIndexed
Source§type Err = ParseIntError
type Err = ParseIntError
Source§fn from_str(s: &str) -> Result<OneIndexed, <OneIndexed as FromStr>::Err>
fn from_str(s: &str) -> Result<OneIndexed, <OneIndexed as FromStr>::Err>
s to return a value of this type. Read more