Skip to main content

BytesRange

Enum BytesRange 

Source
pub enum BytesRange {
    Range {
        offset: u64,
        size: Option<u64>,
    },
    Suffix {
        size: u64,
    },
}
Expand description

BytesRange carries a range of content.

BytesRange implements ToString which can be used as Range HTTP header directly.

<unit> should always be bytes.

Range: bytes=<range-start>-
Range: bytes=<range-start>-<range-end>
Range: bytes=-<suffix-length>

Variants§

§

Range

Read from offset with optional size.

Fields

§offset: u64

Offset of the range.

§size: Option<u64>

Size of the range.

§

Suffix

Read the last size bytes.

Fields

§size: u64

Size of the suffix range.

Implementations§

Source§

impl BytesRange

Source

pub fn new(offset: u64, size: Option<u64>) -> Self

Create a new BytesRange

It better to use BytesRange::from(1024..2048) to construct.

§Note

The behavior for None and Some of size is different.

  • size=None => bytes=<offset>-, read from <offset> until the end
  • size=Some(1024) => bytes=<offset>-<offset + 1024>, read 1024 bytes starting from the <offset>
Source

pub fn suffix(size: u64) -> Self

Create a suffix BytesRange that reads the last size bytes.

Source

pub fn offset(&self) -> u64

Get offset of BytesRange.

Source

pub fn size(&self) -> Option<u64>

Get size of BytesRange.

Source

pub fn is_suffix(&self) -> bool

Returns true if this range is a suffix range.

Source

pub fn advance(&mut self, n: u64)

Advance the range by n bytes.

§Panics

Panic if advancing the offset would overflow or if input n is larger than the size of the range.

Source

pub fn is_full(&self) -> bool

Check if this range is full of this content.

If this range is full, we don’t need to specify it in http request.

Source

pub fn to_header(&self) -> String

Convert bytes range into Range header.

Returns an empty string for a range with no valid HTTP representation – a zero size, or an end that overflows – which Display reports by failing. format! turns a Display failure into a panic, and this runs while a request is being built.

Source

pub fn to_range(&self) -> impl RangeBounds<u64>

Convert bytes range into rust range.

Source

pub fn to_range_as_usize(self) -> impl RangeBounds<usize>

Convert bytes range into rust range with usize.

Source

pub fn to_content_range(self, content_length: usize) -> Result<Range<usize>>

Convert bytes range into a checked content slice range.

Trait Implementations§

Source§

impl Clone for BytesRange

Source§

fn clone(&self) -> BytesRange

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 BytesRange

Source§

impl Debug for BytesRange

Source§

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

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

impl Default for BytesRange

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for BytesRange

Source§

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

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

impl Eq for BytesRange

Source§

impl<T> From<T> for BytesRange
where T: RangeBounds<u64>,

Source§

fn from(range: T) -> Self

Converts to this type from the input type.
Source§

impl FromStr for BytesRange

Source§

type Err = Error

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

fn from_str(value: &str) -> Result<Self>

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

impl PartialEq for BytesRange

Source§

fn eq(&self, other: &BytesRange) -> 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 BytesRange

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = 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.