Skip to main content

Listing

Struct Listing 

Source
pub struct Listing<R> {
    pub rows: Vec<R>,
    pub total: Option<usize>,
    pub cursor: Option<String>,
    pub has_more: Option<bool>,
}
Available on crate features http and validation only.
Expand description

One page of a collection, on its way back to the client.

Storage returns the rows plus whatever it knows about the rest of the collection; the handler turns that into first/prev/next/last links. What is absent is simply not linked — a cursor-paged listing that reports no total gets no last link rather than a wrong one.

Fields§

§rows: Vec<R>

The rows on this page.

§total: Option<usize>

How many rows the whole collection holds, if storage counted.

Drives the last link and meta.total. Leave it None when counting costs a second query you do not want to pay for.

§cursor: Option<String>

Where the next page resumes, for cursor paging.

None means this is the last page, so no next link is emitted. Ignored under offset paging, which derives next from has_more or, failing that, arithmetically.

§has_more: Option<bool>

Whether the collection continues past this page, when storage knows.

Offset paging only, and an override for the next link: without it a full page is assumed to have a successor, so the last full page links to an empty one. Storage that can answer exactly — by reading one row past the page, say — sets this and the guess is not used.

None means “not known”, not “no more”.

Implementations§

Source§

impl<R> Listing<R>

Source

pub fn new(rows: impl IntoIterator<Item = R>) -> Self

A page of rows, with nothing else known about the collection.

Source

pub fn total(self, total: usize) -> Self

How many rows the collection holds in total.

Source

pub fn has_more(self, has_more: bool) -> Self

Whether the collection continues past this page.

Set it when storage knows exactly, and the next link stops being a guess — see has_more.

Source

pub fn cursor(self, cursor: impl Into<String>) -> Self

The cursor the next page resumes from.

Set it only when there is a next page: it is what emits the next link, so a cursor on the final page walks the client into an empty one.

Auto Trait Implementations§

§

impl<R> Freeze for Listing<R>
where Vec<R>: Freeze,

§

impl<R> RefUnwindSafe for Listing<R>
where Vec<R>: RefUnwindSafe,

§

impl<R> Send for Listing<R>
where Vec<R>: Send,

§

impl<R> Sync for Listing<R>
where Vec<R>: Sync,

§

impl<R> Unpin for Listing<R>
where Vec<R>: Unpin,

§

impl<R> UnsafeUnpin for Listing<R>
where Vec<R>: UnsafeUnpin,

§

impl<R> UnwindSafe for Listing<R>
where Vec<R>: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more