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§
Implementations§
Source§impl BytesRange
impl BytesRange
Sourcepub fn new(offset: u64, size: Option<u64>) -> Self
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>
Sourcepub fn advance(&mut self, n: u64)
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.
Sourcepub fn is_full(&self) -> bool
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.
Sourcepub fn to_header(&self) -> String
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.
Sourcepub fn to_range(&self) -> impl RangeBounds<u64>
pub fn to_range(&self) -> impl RangeBounds<u64>
Convert bytes range into rust range.
Sourcepub fn to_range_as_usize(self) -> impl RangeBounds<usize>
pub fn to_range_as_usize(self) -> impl RangeBounds<usize>
Convert bytes range into rust range with usize.
Trait Implementations§
Source§impl Clone for BytesRange
impl Clone for BytesRange
Source§fn clone(&self) -> BytesRange
fn clone(&self) -> BytesRange
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more