pub struct Form { /* private fields */ }Available on crate feature
alloc only.Expand description
The owned result of a urlencoded parse: every field, in input order, duplicates kept.
Every decoded name and value lives in one buffer allocated once, and
one table of positions; neither reallocates. Lookups are linear scans
(there is no hash map, so hash flooding cannot apply; max_fields
bounds every scan). On drop the buffer is wiped. Debug prints names
and value lengths, never values. There is no Clone: a clone would
be a second copy of every secret.
§Examples
let form = form_net::parse_urlencoded(b"role=user&role=admin&tag=red&tag=blue")?;
assert_eq!(form.get("role"), Some("user")); // first wins
assert!(form.get_one("role").is_err()); // strict
assert_eq!(form.get_one("missing")?, None);
assert_eq!(form.get_all("tag").collect::<Vec<_>>(), ["red", "blue"]);
assert_eq!(form.iter().count(), 4);
assert_eq!(
format!("{form:?}"),
"Form { role: <4 bytes>, role: <5 bytes>, tag: <3 bytes>, tag: <4 bytes> }"
);Implementations§
Source§impl Form
impl Form
Sourcepub fn get_all<'f>(
&'f self,
name: &'f str,
) -> impl Iterator<Item = &'f str> + 'f
pub fn get_all<'f>( &'f self, name: &'f str, ) -> impl Iterator<Item = &'f str> + 'f
Every value given for name, in input order.
§Examples
let form = form_net::parse_urlencoded(b"t=a&x=1&t=b")?;
assert_eq!(form.get_all("t").collect::<Vec<_>>(), ["a", "b"]);Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Every (name, value), in input order.
§Examples
let form = form_net::parse_urlencoded(b"a=1&b=2")?;
assert_eq!(form.iter().collect::<Vec<_>>(), [("a", "1"), ("b", "2")]);Sourcepub fn names(&self) -> impl Iterator<Item = &str>
pub fn names(&self) -> impl Iterator<Item = &str>
Every name, in input order, repeats included.
§Examples
let form = form_net::parse_urlencoded(b"a=1&b=2&a=3")?;
assert_eq!(form.names().collect::<Vec<_>>(), ["a", "b", "a"]);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of fields, repeats included.
§Examples
assert_eq!(form_net::parse_urlencoded(b"a&&b")?.len(), 2);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Form
impl RefUnwindSafe for Form
impl Send for Form
impl Sync for Form
impl Unpin for Form
impl UnsafeUnpin for Form
impl UnwindSafe for Form
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