Struct opendal::raw::BytesRange
source · pub struct BytesRange(_, _);
Expand description
BytesRange(offset, size) 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>
Notes
BytesRange support constuct via rust native range syntex like ..
, 1024..
, ..2048
.
But it’s has different symantic on RangeTo
: ..<end>
.
In rust, ..<end>
means all items that < end
, but in BytesRange, ..<end>
means the
tailing part of content, a.k.a, the last <end>
bytes of content.
0..1024
will be converted to headerrange: bytes=0-1024
..1024
will be converted to headerrange: bytes=-1024
Implementations§
source§impl BytesRange
impl BytesRange
sourcepub fn new(offset: Option<u64>, size: Option<u64>) -> Self
pub fn new(offset: Option<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(0)
is different.
- offset=None =>
bytes=-<size>
, read<size>
bytes from end. - offset=Some(0) =>
bytes=0-<size>
, read<size>
bytes from start.
sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Check if this range is full of this object 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.
NOTE
bytes=-1023
means get the suffix of the file.bytes=0-1023
means get the first 1024 bytes, we must set the end to 1023.
sourcepub fn to_range(&self) -> impl RangeBounds<u64>
pub fn to_range(&self) -> impl RangeBounds<u64>
Convert bytes range into rust range.
sourcepub fn apply_on_bytes(&self, bs: Bytes) -> Bytes
pub fn apply_on_bytes(&self, bs: Bytes) -> Bytes
apply_on_bytes will apply range on bytes.
Trait Implementations§
source§impl Clone for BytesRange
impl Clone for BytesRange
source§fn clone(&self) -> BytesRange
fn clone(&self) -> BytesRange
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BytesRange
impl Debug for BytesRange
source§impl Default for BytesRange
impl Default for BytesRange
source§fn default() -> BytesRange
fn default() -> BytesRange
source§impl Display for BytesRange
impl Display for BytesRange
source§impl<T> From<T> for BytesRangewhere
T: RangeBounds<u64>,
impl<T> From<T> for BytesRangewhere
T: RangeBounds<u64>,
source§impl FromStr for BytesRange
impl FromStr for BytesRange
source§impl PartialEq<BytesRange> for BytesRange
impl PartialEq<BytesRange> for BytesRange
source§fn eq(&self, other: &BytesRange) -> bool
fn eq(&self, other: &BytesRange) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for BytesRange
impl Eq for BytesRange
impl StructuralEq for BytesRange
impl StructuralPartialEq for BytesRange
Auto Trait Implementations§
impl RefUnwindSafe for BytesRange
impl Send for BytesRange
impl Sync for BytesRange
impl Unpin for BytesRange
impl UnwindSafe for BytesRange
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.