Skip to main content

Window

Struct Window 

Source
pub struct Window {
    pub from: usize,
    pub count: usize,
    pub of: Option<usize>,
}
Expand description

A window onto a sequence: where it starts, how much it covers, and how long the sequence is when that is known.

The mechanism under two things the vocabulary deliberately keeps apart. A carousel is a window of one frame over children that are all present; a paged list is a window of a page over rows most of which were never fetched. Those are different facts and they stay different types — Showing says which child is up, Paging says where a reader is in a query — but the arithmetic underneath is one piece of code, so a terminal and a browser cannot come to disagree about which frame is last.

§Why of is optional and count is not

count is what is on screen and is therefore always known. of is the length of the thing being windowed, and a host that cannot count says so by leaving it empty for the life of the screen. It is never “not counted yet”: see “First paint is final paint” in the crate header. A total that turns up on a later pass widens the text that prints it.

§Clamping

Every derivation clamps rather than refusing, and a zero count answers None rather than dividing. A window past the end is a bug in the host, and a renderer that answered it by drawing nothing would report a region that vanished, which is the hardest kind of bug to find from what is on screen. Share::percent clamps for the same reason.

Fields§

§from: usize

The index into the sequence where the window starts.

§count: usize

How many the window covers. One, for a carousel.

§of: Option<usize>

How long the sequence is, when the host can say.

Implementations§

Source§

impl Window

Source

pub const fn new(from: usize, count: usize) -> Self

A window of count, starting at from, over a sequence of unknown length.

Source

pub const fn of(self, of: usize) -> Self

How long the sequence is.

Source

pub const fn frame(at: usize, of: usize) -> Self

One item of a sequence whose length is known. A carousel frame.

Source

pub const fn index(self) -> Option<usize>

Which window this is, counting from zero.

None when count is zero, which is the only input with no answer rather than a clamped one.

Source

pub const fn windows(self) -> Option<usize>

How many windows the sequence holds.

None unless both the length and a non-zero count are known. A partial answer here would be a renderer drawing “of 0”.

Source

pub const fn has_before(self) -> bool

Whether anything sits before this window.

Source

pub const fn after(self) -> Option<usize>

How many sit after this window, when the length is known.

Here rather than in each renderer for Showing::selective’s reason: three of them writing the same subtraction is how they come to disagree, and this one has an underflow in it for whoever writes it fourth.

Source

pub const fn has_after(self) -> bool

Whether anything sits after it.

true when the length is unknown: a host that cannot count cannot rule out more, and offering a way forward that turns out to be empty is the cheaper of the two mistakes.

Source

pub const fn clamped(self) -> Self

The window with from brought inside the sequence.

A no-op when the length is unknown, since there is nothing to clamp against.

Trait Implementations§

Source§

impl Clone for Window

Source§

fn clone(&self) -> Window

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 Window

Source§

impl Debug for Window

Source§

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

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

impl Default for Window

Source§

fn default() -> Window

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

impl Eq for Window

Source§

impl PartialEq for Window

Source§

fn eq(&self, other: &Window) -> 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 Window

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, 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.