pub struct RawPair<'a> { /* private fields */ }Expand description
One name=value sequence, undecoded.
Debug prints the offset and the lengths only: values can be secrets.
Implementations§
Source§impl<'a> RawPair<'a>
impl<'a> RawPair<'a>
Sourcepub const fn name_raw(&self) -> &'a [u8] ⓘ
pub const fn name_raw(&self) -> &'a [u8] ⓘ
The name as sent, before decoding.
§Examples
let p = form_net::raw_pairs(b"a+b=1", &form_net::Limits::DEFAULT).next().unwrap()?;
assert_eq!(p.name_raw(), b"a+b");Sourcepub const fn value_raw(&self) -> &'a [u8] ⓘ
pub const fn value_raw(&self) -> &'a [u8] ⓘ
The value as sent, before decoding.
§Examples
let p = form_net::raw_pairs(b"a=%41", &form_net::Limits::DEFAULT).next().unwrap()?;
assert_eq!(p.value_raw(), b"%41");Sourcepub const fn has_equals(&self) -> bool
pub const fn has_equals(&self) -> bool
Whether the sequence contained =: a and a= both have an empty
value, but only a= has an equals sign.
§Examples
use form_net::Limits;
let mut it = form_net::raw_pairs(b"a&b=", &Limits::DEFAULT);
assert!(!it.next().unwrap()?.has_equals());
assert!(it.next().unwrap()?.has_equals());Sourcepub const fn name_needs_decoding(&self) -> bool
pub const fn name_needs_decoding(&self) -> bool
Whether the name contains % or +.
§Examples
let p = form_net::raw_pairs(b"a+b=1", &form_net::Limits::DEFAULT).next().unwrap()?;
assert!(p.name_needs_decoding() && !p.value_needs_decoding());Sourcepub const fn value_needs_decoding(&self) -> bool
pub const fn value_needs_decoding(&self) -> bool
Whether the value contains % or +.
§Examples
let p = form_net::raw_pairs(b"a=1%20", &form_net::Limits::DEFAULT).next().unwrap()?;
assert!(p.value_needs_decoding());Sourcepub fn name_str(&self) -> Option<&'a str>
pub fn name_str(&self) -> Option<&'a str>
The name with no copy, when it needs no decoding and is valid UTF-8.
§Examples
let p = form_net::raw_pairs(b"email=x", &form_net::Limits::DEFAULT).next().unwrap()?;
assert_eq!(p.name_str(), Some("email"));Sourcepub fn value_str(&self) -> Option<&'a str>
pub fn value_str(&self) -> Option<&'a str>
The value with no copy, when it needs no decoding and is valid UTF-8.
§Examples
let p = form_net::raw_pairs(b"q=a+b", &form_net::Limits::DEFAULT).next().unwrap()?;
assert_eq!(p.value_str(), None);Sourcepub fn decode_name<'b>(
&self,
out: &'b mut [u8],
policy: PercentPolicy,
) -> Result<&'b str, FormError>
pub fn decode_name<'b>( &self, out: &'b mut [u8], policy: PercentPolicy, ) -> Result<&'b str, FormError>
Decodes the name into out (see decode_into).
§Errors
Encoding { InvalidPercent | InvalidUtf8 } located in the body;
BufferTooSmall when out is shorter than the raw name.
§Examples
use form_net::PercentPolicy;
let p = form_net::raw_pairs(b"a%20b=1", &form_net::Limits::DEFAULT).next().unwrap()?;
let mut out = [0u8; 16];
assert_eq!(p.decode_name(&mut out, PercentPolicy::Refuse)?, "a b");Sourcepub fn decode_value<'b>(
&self,
out: &'b mut [u8],
policy: PercentPolicy,
) -> Result<&'b str, FormError>
pub fn decode_value<'b>( &self, out: &'b mut [u8], policy: PercentPolicy, ) -> Result<&'b str, FormError>
Decodes the value into out (see decode_into).
§Errors
As decode_name.
§Examples
use form_net::PercentPolicy;
let p = form_net::raw_pairs(b"q=rust+forms", &form_net::Limits::DEFAULT).next().unwrap()?;
let mut out = [0u8; 16];
assert_eq!(p.decode_value(&mut out, PercentPolicy::Refuse)?, "rust forms");Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for RawPair<'a>
impl<'a> RefUnwindSafe for RawPair<'a>
impl<'a> Send for RawPair<'a>
impl<'a> Sync for RawPair<'a>
impl<'a> Unpin for RawPair<'a>
impl<'a> UnsafeUnpin for RawPair<'a>
impl<'a> UnwindSafe for RawPair<'a>
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