ContentRange

Enum ContentRange 

Source
pub enum ContentRange {
    Bytes(ContentRangeBytes),
    UnboundBytes(ContentRangeUnbound),
    Unsatisfied(ContentRangeUnsatisfied),
}
Expand description

HTTP Content-Range response header representation.

Variants§

§

Bytes(ContentRangeBytes)

Regular bytes range response with status 206

§

UnboundBytes(ContentRangeUnbound)

Regular bytes range response with status 206

§

Unsatisfied(ContentRangeUnsatisfied)

Server response with status 416

Implementations§

Source§

impl ContentRange

Source

pub fn parse(header: &str) -> Option<ContentRange>

Parses Content-Range HTTP header string as per RFC 7233.

header is the HTTP Content-Range header (e.g. bytes 0-9/30).

This parser is a bit more lenient than the official RFC, it allows spaces and tabs between everything. See https://httpwg.org/specs/rfc7233.html#rfc.section.4.2

assert_eq!(ContentRange::parse("bytes 42-69/420").unwrap(),
    ContentRange::Bytes(ContentRangeBytes{first_byte: 42, last_byte: 69, complete_length: 420}));

// complete_length is unknown
assert_eq!(ContentRange::parse("bytes 42-69/*").unwrap(),
   ContentRange::UnboundBytes(ContentRangeUnbound{first_byte: 42, last_byte: 69}));

// response is unsatisfied
assert_eq!(ContentRange::parse("bytes */420").unwrap(),
  ContentRange::Unsatisfied(ContentRangeUnsatisfied{complete_length: 420}));
Source

pub fn parse_bytes(header: &[u8]) -> Option<ContentRange>

From https://httpwg.org/specs/rfc7233.html#rfc.section.4.2 Valid bytes responses: Content-Range: bytes 42-1233/1234 Content-Range: bytes 42-1233/* Content-Range: bytes */1233

  Content-Range       = byte-content-range
                      / other-content-range

  byte-content-range  = bytes-unit SP
                        ( byte-range-resp / unsatisfied-range )

  byte-range-resp     = byte-range "/" ( complete-length / "*" )
  byte-range          = first-byte-pos "-" last-byte-pos
  unsatisfied-range   = "*/" complete-length

  complete-length     = 1*DIGIT

  other-content-range = other-range-unit SP other-range-resp
  other-range-resp    = *CHAR

Same as parse but parses directly from the byte array

Trait Implementations§

Source§

impl Clone for ContentRange

Source§

fn clone(&self) -> ContentRange

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContentRange

Source§

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

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

impl FromStr for ContentRange

Source§

type Err = ()

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

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

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

impl PartialEq for ContentRange

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for ContentRange

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for ContentRange

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for ContentRange

Source§

impl Eq for ContentRange

Source§

impl StructuralPartialEq for ContentRange

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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.