Skip to main content

Boundary

Struct Boundary 

Source
pub struct Boundary(/* private fields */);
Expand description

A multipart boundary, as RFC 2046 section 5.1.1 defines it: 1 to 70 characters from a restricted set, not ending in a space.

use base_web_multipart::Boundary;
use base_web_media_type::MediaType;

let media_type = MediaType::parse("multipart/form-data; boundary=\"simple boundary\"")?;
let boundary = Boundary::from_media_type(&media_type)?;
assert_eq!(boundary.as_str(), "simple boundary");

let generated = Boundary::generate();
assert_eq!(generated.as_str().len(), 32);
assert_eq!(generated.form_data_media_type().parameter("boundary"), Some(generated.as_str()));

Implementations§

Source§

impl Boundary

Source

pub const LENGTH_LIMIT: usize = 70

The longest boundary RFC 2046 allows.

Source

pub fn new(text: &str) -> Result<Self, BoundaryError>

A boundary from text.

§Errors

BoundaryError::Invalid when the text is not a boundary RFC 2046 allows.

Source

pub fn from_media_type(media_type: &MediaType) -> Result<Self, BoundaryError>

The boundary of a multipart media type, from its boundary parameter.

§Errors

BoundaryError::NotMultipart for another type, BoundaryError::Missing when there is no boundary parameter, and BoundaryError::Invalid when it is not a valid boundary.

Source

pub fn generate() -> Self

A new boundary of 192 random bits from the operating system, written as 32 URL-safe base64 characters, so that content cannot contain it by chance or by an attacker’s design.

§Panics

When the operating system’s random number generator fails, which it does not on supported platforms; the standard library’s hash maps rely on it in the same way.

Source

pub fn as_str(&self) -> &str

The boundary as text.

Source

pub fn to_media_type(&self, subtype: &str) -> Result<MediaType, MediaTypeError>

The media type multipart/{subtype} with this boundary as its parameter, such as multipart/mixed; boundary=....

§Errors

When the subtype is not a token, or is a wildcard.

Source

pub fn form_data_media_type(&self) -> MediaType

The media type multipart/form-data with this boundary as its parameter.

Trait Implementations§

Source§

impl AsRef<str> for Boundary

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
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 Debug for Boundary

Source§

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

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

impl Display for Boundary

Source§

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

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

impl Eq for Boundary

Source§

impl FromStr for Boundary

Source§

type Err = BoundaryError

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Boundary

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.