Skip to main content

OneBased

Struct OneBased 

Source
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

Source

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.

Source

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.

Source

pub const fn get(self) -> u16

Returns the stored one-based value.

Source

pub const fn get_zero_based(self) -> u16

Converts the stored terminal value back to a zero-based application index.

Trait Implementations§

Source§

impl Clone for OneBased

Source§

fn clone(&self) -> OneBased

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for OneBased

Source§

impl Debug for OneBased

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OneBased

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for OneBased

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for OneBased

Source§

impl From<NonZero<u16>> for OneBased

Source§

fn from(n: NonZeroU16) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for OneBased

Source§

fn eq(&self, other: &OneBased) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OneBased

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.