Struct rocket::form::name::NameView [−][src]
pub struct NameView<'v> { /* fields omitted */ }
Expand description
A sliding-prefix view into a Name
.
A NameView
maintains a sliding key view into a Name
. The current key
(key()
) can be shift()
ed one key to the right.
The Name
prefix including the current key can be extracted via
as_name()
and the prefix not including the current key via
parent()
.
This is best illustrated via an example:
use rocket::form::name::NameView; // The view begins at the first key. Illustrated: `(a).b[c:d]` where // parenthesis enclose the current key. let mut view = NameView::new("a.b[c:d]"); assert_eq!(view.key().unwrap(), "a"); assert_eq!(view.as_name(), "a"); assert_eq!(view.parent(), None); // Shifted once to the right views the second key: `a.(b)[c:d]`. view.shift(); assert_eq!(view.key().unwrap(), "b"); assert_eq!(view.as_name(), "a.b"); assert_eq!(view.parent().unwrap(), "a"); // Shifting again now has predictable results: `a.b[(c:d)]`. view.shift(); assert_eq!(view.key().unwrap(), "c:d"); assert_eq!(view.as_name(), "a.b[c:d]"); assert_eq!(view.parent().unwrap(), "a.b"); // Shifting past the end means we have no further keys. view.shift(); assert_eq!(view.key(), None); assert_eq!(view.key_lossy(), ""); assert_eq!(view.as_name(), "a.b[c:d]"); assert_eq!(view.parent().unwrap(), "a.b[c:d]"); view.shift(); assert_eq!(view.key(), None); assert_eq!(view.as_name(), "a.b[c:d]"); assert_eq!(view.parent().unwrap(), "a.b[c:d]");
Equality
PartialEq
, Eq
, and Hash
all operate on the name prefix including the
current key. Only key values are compared; delimiters are insignificant.
Again, illustrated via examples:
use rocket::form::name::NameView; let mut view = NameView::new("a.b[c:d]"); assert_eq!(view, "a"); // Shifted once to the right views the second key: `a.(b)[c:d]`. view.shift(); assert_eq!(view.key().unwrap(), "b"); assert_eq!(view.as_name(), "a.b"); assert_eq!(view, "a.b"); assert_eq!(view, "a[b]"); // Shifting again now has predictable results: `a.b[(c:d)]`. view.shift(); assert_eq!(view, "a.b[c:d]"); assert_eq!(view, "a.b.c:d"); assert_eq!(view, "a[b].c:d"); assert_eq!(view, "a[b]c:d");
Implementations
Initializes a new NameView
at the first key of name
.
Example
use rocket::form::name::NameView; let mut view = NameView::new("a.b[c:d]"); assert_eq!(view.key().unwrap(), "a"); assert_eq!(view.as_name(), "a"); assert_eq!(view.parent(), None);
Shifts the current key once to the right.
Examples
use rocket::form::name::NameView; let mut view = NameView::new("a.b[c:d][d.e]"); assert_eq!(view.key().unwrap(), "a"); view.shift(); assert_eq!(view.key().unwrap(), "b"); view.shift(); assert_eq!(view.key().unwrap(), "c:d"); view.shift(); assert_eq!(view.key().unwrap(), "d.e");
Malformed strings can have interesting results:
use rocket::form::name::NameView; let mut view = NameView::new("a[c.d"); assert_eq!(view.key_lossy(), "a"); view.shift(); assert_eq!(view.key_lossy(), "c.d"); let mut view = NameView::new("a[c[.d]"); assert_eq!(view.key_lossy(), "a"); view.shift(); assert_eq!(view.key_lossy(), "c[.d"); view.shift(); assert_eq!(view.key(), None); let mut view = NameView::new("foo[c[.d]]"); assert_eq!(view.key_lossy(), "foo"); view.shift(); assert_eq!(view.key_lossy(), "c[.d"); view.shift(); assert_eq!(view.key_lossy(), "]"); view.shift(); assert_eq!(view.key(), None);
Returns the key currently viewed by self
if it is non-empty.
Example
use rocket::form::name::NameView; let mut view = NameView::new("a[b]"); assert_eq!(view.key().unwrap(), "a"); view.shift(); assert_eq!(view.key().unwrap(), "b"); view.shift(); assert_eq!(view.key(), None);
Returns the key currently viewed by self
, even if it is non-empty.
Example
use rocket::form::name::NameView; let mut view = NameView::new("a[b]"); assert_eq!(view.key_lossy(), "a"); view.shift(); assert_eq!(view.key_lossy(), "b"); view.shift(); assert_eq!(view.key_lossy(), "");
Returns the Name
up to and including the current key.
Example
use rocket::form::name::NameView; let mut view = NameView::new("a[b]"); assert_eq!(view.as_name(), "a"); view.shift(); assert_eq!(view.as_name(), "a[b]");
Returns the Name
prior to the current key.
Example
use rocket::form::name::NameView; let mut view = NameView::new("a[b]"); assert_eq!(view.parent(), None); view.shift(); assert_eq!(view.parent().unwrap(), "a"); view.shift(); assert_eq!(view.parent().unwrap(), "a[b]");
Trait Implementations
Auto Trait Implementations
impl<'v> RefUnwindSafe for NameView<'v>
impl<'v> UnwindSafe for NameView<'v>
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Converts self
into a collection.
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V