pub struct Param { /* private fields */ }Expand description
One control at the top of a view.
Implementations§
Source§impl Param
impl Param
Sourcepub fn select(
key: impl Into<String>,
label: impl Into<String>,
options: impl IntoIterator<Item = impl Into<SelectOption>>,
) -> Self
pub fn select( key: impl Into<String>, label: impl Into<String>, options: impl IntoIterator<Item = impl Into<SelectOption>>, ) -> Self
A choice among options, which are rebuilt on every request like a schema is, so a select can be filled from a table.
Examples found in repository?
examples/library/main.rs (line 561)
534 fn params(&self, ctx: &Context, asked: &ViewArgs) -> Result<Vec<Param>, ApiError> {
535 let branches = Self::branches(ctx)?;
536 let options: Vec<SelectOption> = branches
537 .iter()
538 .map(|b| SelectOption::labelled(&b.code, &b.name))
539 .collect();
540 let first = branches.first().map(|b| b.code.clone()).unwrap_or_default();
541
542 // A genre and one of its subgenres. The second list follows the first
543 // one's answer, which is why `params` is told what was asked before
544 // anything is settled. A subgenre belonging to the genre chosen last
545 // time is no answer to the question being asked now, and falls back to
546 // every subgenre of the genre chosen this time.
547 let genres: Vec<Genre> = ctx.optional_rows(GENRES_FILE)?;
548 let mut named: Vec<&str> = genres.iter().map(|g| g.genre.as_str()).collect();
549 named.sort_unstable();
550 named.dedup();
551
552 let chosen = asked.get_or("genre", "");
553 let mut subgenres: Vec<&str> = genres
554 .iter()
555 .filter(|g| g.genre == chosen)
556 .map(|g| g.subgenre.as_str())
557 .collect();
558 subgenres.sort_unstable();
559
560 Ok(vec![
561 Param::select("branch", "Branch", options).default(first),
562 Param::select("genre", "Genre", Self::any("Every genre", named)).default(""),
563 Param::select(
564 "subgenre",
565 "Subgenre",
566 Self::any("Every subgenre", subgenres),
567 )
568 .default(""),
569 Param::string("author", "Author"),
570 ])
571 }Sourcepub fn string(key: impl Into<String>, label: impl Into<String>) -> Self
pub fn string(key: impl Into<String>, label: impl Into<String>) -> Self
Examples found in repository?
examples/library/main.rs (line 569)
534 fn params(&self, ctx: &Context, asked: &ViewArgs) -> Result<Vec<Param>, ApiError> {
535 let branches = Self::branches(ctx)?;
536 let options: Vec<SelectOption> = branches
537 .iter()
538 .map(|b| SelectOption::labelled(&b.code, &b.name))
539 .collect();
540 let first = branches.first().map(|b| b.code.clone()).unwrap_or_default();
541
542 // A genre and one of its subgenres. The second list follows the first
543 // one's answer, which is why `params` is told what was asked before
544 // anything is settled. A subgenre belonging to the genre chosen last
545 // time is no answer to the question being asked now, and falls back to
546 // every subgenre of the genre chosen this time.
547 let genres: Vec<Genre> = ctx.optional_rows(GENRES_FILE)?;
548 let mut named: Vec<&str> = genres.iter().map(|g| g.genre.as_str()).collect();
549 named.sort_unstable();
550 named.dedup();
551
552 let chosen = asked.get_or("genre", "");
553 let mut subgenres: Vec<&str> = genres
554 .iter()
555 .filter(|g| g.genre == chosen)
556 .map(|g| g.subgenre.as_str())
557 .collect();
558 subgenres.sort_unstable();
559
560 Ok(vec![
561 Param::select("branch", "Branch", options).default(first),
562 Param::select("genre", "Genre", Self::any("Every genre", named)).default(""),
563 Param::select(
564 "subgenre",
565 "Subgenre",
566 Self::any("Every subgenre", subgenres),
567 )
568 .default(""),
569 Param::string("author", "Author"),
570 ])
571 }Sourcepub fn default(self, value: impl Into<String>) -> Self
pub fn default(self, value: impl Into<String>) -> Self
What the view is asked for when the address names nothing.
Examples found in repository?
examples/library/main.rs (line 561)
534 fn params(&self, ctx: &Context, asked: &ViewArgs) -> Result<Vec<Param>, ApiError> {
535 let branches = Self::branches(ctx)?;
536 let options: Vec<SelectOption> = branches
537 .iter()
538 .map(|b| SelectOption::labelled(&b.code, &b.name))
539 .collect();
540 let first = branches.first().map(|b| b.code.clone()).unwrap_or_default();
541
542 // A genre and one of its subgenres. The second list follows the first
543 // one's answer, which is why `params` is told what was asked before
544 // anything is settled. A subgenre belonging to the genre chosen last
545 // time is no answer to the question being asked now, and falls back to
546 // every subgenre of the genre chosen this time.
547 let genres: Vec<Genre> = ctx.optional_rows(GENRES_FILE)?;
548 let mut named: Vec<&str> = genres.iter().map(|g| g.genre.as_str()).collect();
549 named.sort_unstable();
550 named.dedup();
551
552 let chosen = asked.get_or("genre", "");
553 let mut subgenres: Vec<&str> = genres
554 .iter()
555 .filter(|g| g.genre == chosen)
556 .map(|g| g.subgenre.as_str())
557 .collect();
558 subgenres.sort_unstable();
559
560 Ok(vec![
561 Param::select("branch", "Branch", options).default(first),
562 Param::select("genre", "Genre", Self::any("Every genre", named)).default(""),
563 Param::select(
564 "subgenre",
565 "Subgenre",
566 Self::any("Every subgenre", subgenres),
567 )
568 .default(""),
569 Param::string("author", "Author"),
570 ])
571 }pub fn key(&self) -> &str
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Param
impl RefUnwindSafe for Param
impl Send for Param
impl Sync for Param
impl Unpin for Param
impl UnsafeUnpin for Param
impl UnwindSafe for Param
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more