Skip to main content

Query

Enum Query 

Source
#[non_exhaustive]
pub enum Query<'r> { Absent, Null, One(&'r str), Many(&'r [Option<String>]), }
Available on crate feature router only.
Expand description

One value of route.query, as vue-router parses it: a key may be absent, given without a value (?flag, which is null), given once, or given more than once, which makes an array.

§Example

use ferrovue::{Query, Router};

let router = Router::new(&["/search"]);
let route = router.at("/search?q=rust&tag=a&tag=b&flag");

assert_eq!(route.query("q"), Query::One("rust"));
assert_eq!(route.query("flag"), Query::Null);
assert_eq!(route.query("nothing"), Query::Absent);
assert!(route.query("tag").is_array());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Absent

No such key: undefined.

§

Null

?flag: null.

§

One(&'r str)

?q=text, decoded.

§

Many(&'r [Option<String>])

?q=a&q=b: an array, in which a value written without = is null.

Implementations§

Source§

impl<'r> Query<'r>

Source

pub fn write_display(&self, out: &mut String)

{{ route.query.q }}, escaped: nothing for undefined and null, the text for a string, and an array as toDisplayString writes one: JSON.stringify(value, null, 2).

§Example
let router = ferrovue::Router::new(&["/search"]);
let route = router.at("/search?q=a%3Cb&tag=x&tag=y");

let mut out = String::new();
route.query("q").write_display(&mut out);
assert_eq!(out, "a&lt;b");

out.clear();
route.query("tag").write_display(&mut out);
assert_eq!(out, "[\n  &quot;x&quot;,\n  &quot;y&quot;\n]");
Source

pub fn truthy(&self) -> bool

JavaScript’s truthiness: a non-empty string or an array.

§Example
use ferrovue::Query;

assert!(Query::One("x").truthy());
assert!(!Query::One("").truthy());
assert!(!Query::Null.truthy() && !Query::Absent.truthy());
Source

pub fn is(&self, text: &str) -> bool

route.query.q === text: only a single value can equal a string.

Source

pub fn is_undefined(&self) -> bool

route.query.q === undefined.

Source

pub fn is_array(&self) -> bool

Array.isArray(route.query.q).

Source

pub fn or<'a>(self, fallback: &'a str) -> Query<'a>
where 'r: 'a,

route.query.q ?? fallback: the fallback for undefined and null.

§Example
use ferrovue::Query;

assert_eq!(Query::Absent.or("none"), Query::One("none"));
assert_eq!(Query::One("").or("none"), Query::One("")); // `??` keeps the empty string
Source

pub fn attr_value(&self) -> Option<&'r str>

The single string, when the value is one: typeof route.query.q === "string", which narrows it to what an attribute can be bound to. null, undefined and an array are None.

§Example
use ferrovue::Query;

assert_eq!(Query::One("rust").attr_value(), Some("rust"));
assert_eq!(Query::Null.attr_value(), None);

Trait Implementations§

Source§

impl<'r> Clone for Query<'r>

Source§

fn clone(&self) -> Query<'r>

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<'r> Copy for Query<'r>

Source§

impl<'r> Debug for Query<'r>

Source§

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

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

impl<'r> PartialEq for Query<'r>

Source§

fn eq(&self, other: &Query<'r>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<'r> StructuralPartialEq for Query<'r>

Auto Trait Implementations§

§

impl<'r> Freeze for Query<'r>

§

impl<'r> RefUnwindSafe for Query<'r>

§

impl<'r> Send for Query<'r>

§

impl<'r> Sync for Query<'r>

§

impl<'r> Unpin for Query<'r>

§

impl<'r> UnsafeUnpin for Query<'r>

§

impl<'r> UnwindSafe for Query<'r>

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
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.
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