#[non_exhaustive]pub enum Query<'r> {
Absent,
Null,
One(&'r str),
Many(&'r [Option<String>]),
}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
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>
impl<'r> Query<'r>
Sourcepub fn write_display(&self, out: &mut String)
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<b");
out.clear();
route.query("tag").write_display(&mut out);
assert_eq!(out, "[\n "x",\n "y"\n]");Sourcepub fn truthy(&self) -> bool
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());Sourcepub fn is(&self, text: &str) -> bool
pub fn is(&self, text: &str) -> bool
route.query.q === text: only a single value can equal a string.
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
route.query.q === undefined.
Sourcepub fn or<'a>(self, fallback: &'a str) -> Query<'a>where
'r: 'a,
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 stringSourcepub fn attr_value(&self) -> Option<&'r str>
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);