pub struct Range {
pub start: u64,
pub end: u64,
}Expand description
A byte range within a resource (start..end).
Fields§
§start: u64§end: u64Implementations§
Source§impl Range
impl Range
pub const STRING_SEPARATOR: &'static str = "String_separator"
pub const BOUNDARY: &'static str = "boundary"
pub const BYTERANGES: &'static str = "byteranges"
pub const MULTIPART: &'static str = "multipart"
pub const BYTES: &'static str = "bytes"
pub const MULTIPART_BYTERANGES_CONTENT_TYPE: &'static str = "multipart/byteranges; boundary=String_separator"
pub const _ERROR_NO_EMPTY_LINE_BETWEEN_CONTENT_RANGE_HEADER_AND_BODY: &'static str = "no empty line between content range headers and body"
pub const _ERROR_UNABLE_TO_PARSE_CONTENT_RANGE: &'static str = "unable to parse content-range"
pub const ERROR_START_IS_AFTER_END_CONTENT_RANGE: &'static str = "start is after end in content range"
pub const ERROR_START_IS_BIGGER_THAN_FILESIZE_CONTENT_RANGE: &'static str = "start is bigger than filesize in content range"
pub const ERROR_END_IS_BIGGER_THAN_FILESIZE_CONTENT_RANGE: &'static str = "end is bigger than filesize in content range"
pub const ERROR_MALFORMED_RANGE_HEADER_WRONG_UNIT: &'static str = "range header malformed, most likely you have an error in unit statement"
pub const ERROR_UNABLE_TO_PARSE_RANGE_START: &'static str = "unable to parse range start"
pub const ERROR_UNABLE_TO_PARSE_RANGE_END: &'static str = "unable to parse range end"
Sourcepub const MAX_RANGES: usize = 16
pub const MAX_RANGES: usize = 16
The most ranges served as parts; more become one range of the whole file (RFC 9110 §14.2 lets a server coalesce or ignore ranges).
Sourcepub fn parse_range_in_content_range(
filelength: u64,
range_str: &str,
) -> Result<Range, Error>
pub fn parse_range_in_content_range( filelength: u64, range_str: &str, ) -> Result<Range, Error>
Parse one first-last / first- / -suffix byte range against a
resource of filelength bytes (RFC 9110 §14.1.2). The returned end
is inclusive (bytes=0-0 is one byte). A last past the end is
clamped to the last byte and a suffix longer than the resource selects
all of it; a range starting at or past the end, first > last, or any
range on an empty resource is 416 Range Not Satisfiable.
pub fn parse_content_range( filepath: &str, filelength: u64, raw_range_value: &str, ) -> Result<Vec<ContentRange>, Error>
Sourcepub fn coalesce(ranges: Vec<Range>, filelength: u64) -> Vec<Range>
pub fn coalesce(ranges: Vec<Range>, filelength: u64) -> Vec<Range>
ranges (inclusive ends) as served: kept as requested when none
overlap; otherwise sorted with the overlapping ones merged — so a
response never holds more bytes than the file has; and more than
MAX_RANGES parts become the whole file.
pub fn get_content_range_list( request_uri: &str, range: &Header, ) -> Result<Vec<ContentRange>, Error>
pub fn _parse_multipart_body( cursor: &mut Cursor<&[u8]>, content_range_list: Vec<ContentRange>, ) -> Result<Vec<ContentRange>, String>
pub fn _parse_raw_content_range_header_value( unparsed_header_value: &str, ) -> Result<(i64, i64, i64), String>
pub fn _parse_content_range_header_value( header_value: String, ) -> Result<(i64, i64, i64), String>
pub fn _parse_line_as_bytes(cursor: &mut Cursor<&[u8]>) -> Vec<u8> ⓘ
pub fn _convert_bytes_array_to_string(buffer: Vec<u8>) -> String
Sourcepub fn get_content_range(body: Vec<u8>, mime_type: String) -> ContentRange
pub fn get_content_range(body: Vec<u8>, mime_type: String) -> ContentRange
Creates a ContentRange from raw bytes and a MIME type. The most common way to build a response body.
Sourcepub fn get_content_range_of_a_file(
filepath: &str,
) -> Result<ContentRange, String>
pub fn get_content_range_of_a_file( filepath: &str, ) -> Result<ContentRange, String>
Creates a ContentRange by reading a file from disk. MIME type is detected from the extension.
pub fn parse_multipart_body( cursor: &mut Cursor<&[u8]>, content_range_list: Vec<ContentRange>, ) -> Result<Vec<ContentRange>, String>
pub fn parse_multipart_body_with_boundary( cursor: &mut Cursor<&[u8]>, content_range_list: Vec<ContentRange>, boundary: String, total_bytes: i32, bytes_read: i32, is_opening_boundary_read: bool, ) -> Result<Vec<ContentRange>, String>
pub fn parse_line_as_bytes( cursor: &mut Cursor<&[u8]>, ) -> Result<Vec<u8>, String>
pub fn convert_bytes_array_to_string(buffer: Vec<u8>) -> Result<String, String>
Trait Implementations§
impl Eq for Range
impl StructuralPartialEq for Range
Auto Trait Implementations§
impl Freeze for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnsafeUnpin for Range
impl UnwindSafe for Range
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.