Skip to main content

CardGroup

Struct CardGroup 

Source
pub struct CardGroup { /* private fields */ }
Expand description

A run of cards under a heading, with the count of them.

Implementations§

Source§

impl CardGroup

Source

pub fn new(heading: impl Into<String>) -> Self

Examples found in repository?
examples/library/main.rs (line 716)
683    fn render(&self, _args: &ViewArgs, ctx: &Context) -> Result<ViewData, ApiError> {
684        let branches: Vec<Branch> = ctx.optional_rows(BRANCHES_FILE)?;
685        let books: Vec<Book> = ctx.optional_rows(BOOKS_FILE)?;
686
687        let card = |branch: &Branch| {
688            let (here, out) = shelf_counts(&books, &branch.code);
689            let open = branch.open.unwrap_or(false);
690            let mut card = Card::new(branch.name.as_str())
691                .status(if open {
692                    Status::new("Open", Tone::Good)
693                } else {
694                    // A shut branch is a fact about it rather than a fault, so
695                    // it is neutral—which is also what reads quieter.
696                    Status::new("Shut", Tone::Neutral)
697                })
698                .identifier(branch.code.as_str())
699                .subtitle(format!(
700                    "{}, {} staff",
701                    librarian(branch),
702                    branch.staff.unwrap_or(0)
703                ))
704                .row("Books here", here)
705                .row("Out on loan", out)
706                .link(ViewLink::new("branch").arg("branch", &branch.code));
707            if branch.hours.is_empty() {
708                card = card.sentence(
709                    "No opening hours are recorded, so nothing here says when it can be visited.",
710                );
711            }
712            card
713        };
714
715        let group = |heading: &str, open: bool| {
716            CardGroup::new(heading).cards(
717                branches
718                    .iter()
719                    .filter(|b| b.open.unwrap_or(false) == open)
720                    .map(&card),
721            )
722        };
723
724        Ok(ViewData::new()
725            .note("A card is a branch. Open one for what it holds and what is out.")
726            .group(group("Open", true))
727            .group(group("Shut", false)))
728    }
Source

pub fn card(self, card: Card) -> Self

Source

pub fn cards(self, cards: impl IntoIterator<Item = Card>) -> Self

Examples found in repository?
examples/library/main.rs (lines 716-721)
683    fn render(&self, _args: &ViewArgs, ctx: &Context) -> Result<ViewData, ApiError> {
684        let branches: Vec<Branch> = ctx.optional_rows(BRANCHES_FILE)?;
685        let books: Vec<Book> = ctx.optional_rows(BOOKS_FILE)?;
686
687        let card = |branch: &Branch| {
688            let (here, out) = shelf_counts(&books, &branch.code);
689            let open = branch.open.unwrap_or(false);
690            let mut card = Card::new(branch.name.as_str())
691                .status(if open {
692                    Status::new("Open", Tone::Good)
693                } else {
694                    // A shut branch is a fact about it rather than a fault, so
695                    // it is neutral—which is also what reads quieter.
696                    Status::new("Shut", Tone::Neutral)
697                })
698                .identifier(branch.code.as_str())
699                .subtitle(format!(
700                    "{}, {} staff",
701                    librarian(branch),
702                    branch.staff.unwrap_or(0)
703                ))
704                .row("Books here", here)
705                .row("Out on loan", out)
706                .link(ViewLink::new("branch").arg("branch", &branch.code));
707            if branch.hours.is_empty() {
708                card = card.sentence(
709                    "No opening hours are recorded, so nothing here says when it can be visited.",
710                );
711            }
712            card
713        };
714
715        let group = |heading: &str, open: bool| {
716            CardGroup::new(heading).cards(
717                branches
718                    .iter()
719                    .filter(|b| b.open.unwrap_or(false) == open)
720                    .map(&card),
721            )
722        };
723
724        Ok(ViewData::new()
725            .note("A card is a branch. Open one for what it holds and what is out.")
726            .group(group("Open", true))
727            .group(group("Shut", false)))
728    }
Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Clone for CardGroup

Source§

fn clone(&self) -> Self

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 Debug for CardGroup

Source§

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

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

impl Serialize for CardGroup

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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 = !

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.