pub struct OneBased(/* private fields */);Expand description
A one-based terminal coordinate or dimension.
Terminal protocols generally count rows and columns from 1, while Rust collections and many
application models count from 0. OneBased stores the protocol value and rejects zero. Use
Self::from_zero_based when converting from an application index and Self::get_zero_based
when converting back.
§Examples
use termina::OneBased;
let column = OneBased::from_zero_based(4);
assert_eq!(column.get(), 5);
assert_eq!(column.get_zero_based(), 4);
assert!(OneBased::new(0).is_none());§Implementation Notes
This reimplements the coordinate helper from termwiz escape helpers on top of
NonZeroU16.
Implementations§
Source§impl OneBased
impl OneBased
Sourcepub const fn new(n: u16) -> Option<Self>
pub const fn new(n: u16) -> Option<Self>
Creates a one-based value from an already one-based integer.
Returns None for zero because zero is not a valid terminal row, column, or dimension in
the escape sequences modeled by Termina.
Sourcepub const fn from_zero_based(n: u16) -> Self
pub const fn from_zero_based(n: u16) -> Self
Converts a zero-based application index into a one-based terminal value.
This panics when n is u16::MAX, because adding one would overflow the stored
NonZeroU16.
Sourcepub const fn get_zero_based(self) -> u16
pub const fn get_zero_based(self) -> u16
Converts the stored terminal value back to a zero-based application index.