pub enum ByteRange {
Full,
Part(u64, u64),
Unsatisfiable,
}Expand description
What a Range header asks for, for a body of a known length.
Variants§
Full
No range, another unit or several ranges: the whole body with 200.
Part(u64, u64)
First and last byte, inclusive: 206.
Unsatisfiable
A bytes range that is malformed or starts past the end: 416.
Implementations§
Source§impl ByteRange
impl ByteRange
Sourcepub fn parse(header: Option<&str>, len: u64) -> ByteRange
pub fn parse(header: Option<&str>, len: u64) -> ByteRange
Reads a single bytes= range: a-b, a- or the suffix -n.
use zeyn::ByteRange;
assert_eq!(ByteRange::parse(Some("bytes=0-99"), 1000), ByteRange::Part(0, 99));
assert_eq!(ByteRange::parse(Some("bytes=-500"), 1000), ByteRange::Part(500, 999));
assert_eq!(ByteRange::parse(Some("bytes=900-"), 1000), ByteRange::Part(900, 999));
assert_eq!(ByteRange::parse(Some("bytes=0-5000"), 1000), ByteRange::Part(0, 999));
assert_eq!(ByteRange::parse(Some("bytes=1000-"), 1000), ByteRange::Unsatisfiable);
assert_eq!(ByteRange::parse(Some("bytes=5-1"), 1000), ByteRange::Unsatisfiable);
assert_eq!(ByteRange::parse(Some("bytes=0-1,5-6"), 1000), ByteRange::Full);
assert_eq!(ByteRange::parse(None, 1000), ByteRange::Full);Trait Implementations§
impl Copy for ByteRange
impl Eq for ByteRange
impl StructuralPartialEq for ByteRange
Auto Trait Implementations§
impl Freeze for ByteRange
impl RefUnwindSafe for ByteRange
impl Send for ByteRange
impl Sync for ByteRange
impl Unpin for ByteRange
impl UnsafeUnpin for ByteRange
impl UnwindSafe for ByteRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more