pub struct OneIndexed(/* 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 moreSource§impl Hash for OneIndexed
impl Hash for OneIndexed
Source§impl Ord for OneIndexed
impl Ord for OneIndexed
Source§fn cmp(&self, other: &OneIndexed) -> Ordering
fn cmp(&self, other: &OneIndexed) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for OneIndexed
impl PartialEq for OneIndexed
Source§impl PartialOrd for OneIndexed
impl PartialOrd for OneIndexed
impl Copy for OneIndexed
impl Eq for OneIndexed
impl StructuralPartialEq for OneIndexed
Auto Trait Implementations§
impl Freeze for OneIndexed
impl RefUnwindSafe for OneIndexed
impl Send for OneIndexed
impl Sync for OneIndexed
impl Unpin for OneIndexed
impl UnsafeUnpin for OneIndexed
impl UnwindSafe for OneIndexed
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
Source§impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
fn rounding_into(self, rm: RoundingMode) -> (U, Ordering)
Source§impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
fn saturating_into(self) -> U
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more