Skip to main content

RawPair

Struct RawPair 

Source
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>

Source

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");
Source

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");
Source

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());
Source

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());
Source

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());
Source

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"));
Source

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);
Source

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");
Source

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");
Source

pub const fn offset(&self) -> u64

The byte offset of the sequence in the body.

§Examples
let mut it = form_net::raw_pairs(b"a=1&bb=2", &form_net::Limits::DEFAULT);
let _ = it.next();
assert_eq!(it.next().unwrap()?.offset(), 4);

Trait Implementations§

Source§

impl<'a> Clone for RawPair<'a>

Source§

fn clone(&self) -> Self

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<'a> Copy for RawPair<'a>

Source§

impl Debug for RawPair<'_>

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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<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.