Skip to main content

Boundary

Struct Boundary 

Source
pub struct Boundary { /* private fields */ }
Expand description

A validated boundary with its delimiter (CRLF "--" boundary, 5 to 74 bytes) and the failure table of the streaming matcher, built once.

Debug prints the boundary: it is not secret.

§Examples

use form_net::Boundary;

let b = Boundary::new(b"----WebKitFormBoundaryx7Y")?;
assert_eq!(b.delimiter(), b"\r\n------WebKitFormBoundaryx7Y");
assert!(Boundary::new(b"").is_err());
assert!(Boundary::new(&[b'a'; 71]).is_err());
assert!(Boundary::new(b"ends with space ").is_err());
assert!(Boundary::new(b"has\"quote").is_err());
assert_eq!(Boundary::parse(b"multipart/form-data; boundary=\"a b\"")?.as_bytes(), b"a b");

Implementations§

Source§

impl Boundary

Source

pub fn new(boundary: &[u8]) -> Result<Boundary, FormError>

Validates a bare boundary (without --): 1 to 70 bytes of RFC 2046 bchars, not ending in a space.

§Errors

Syntax { InvalidBoundary }, at the offending byte.

§Examples
assert_eq!(form_net::Boundary::new(b"X")?.delimiter(), b"\r\n--X");
Source

pub fn parse(content_type: &[u8]) -> Result<Boundary, FormError>

Reads the boundary from a whole multipart/form-data Content-Type value.

§Errors

UnsupportedMediaType for any other media type; Syntax { InvalidContentType | MissingBoundary | DuplicateBoundary | InvalidBoundary }.

§Examples
let b = form_net::Boundary::parse(b"multipart/form-data; boundary=----x")?;
assert_eq!(b.as_bytes(), b"----x");
assert!(form_net::Boundary::parse(b"text/plain").is_err());
Source

pub fn as_bytes(&self) -> &[u8] ⓘ

The boundary, without --.

§Examples
assert_eq!(form_net::Boundary::new(b"abc")?.as_bytes(), b"abc");
Source

pub fn delimiter(&self) -> &[u8] ⓘ

The full delimiter: CRLF, --, and the boundary.

§Examples
assert_eq!(form_net::Boundary::new(b"abc")?.delimiter(), b"\r\n--abc");

Trait Implementations§

Source§

impl Clone for Boundary

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 Copy for Boundary

Source§

impl Debug for Boundary

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Boundary

Source§

impl PartialEq for Boundary

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Boundary

Auto Trait Implementations§

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.