| 1 | //! # http-range |
| 2 | //! |
| 3 | //! HTTP Range header parser. |
| 4 | //! Inspired by Go's net/http library. |
| 5 | |
| 6 | static PREFIXrust-analyzer cargo http-range 0.1.5 PREFIX.: &'static [u8] = b"bytes="; |
| 7 | const PREFIX_LENrust-analyzer cargo http-range 0.1.5 PREFIX_LEN.: usize = 6; |
| 8 | |
| 9 | /// Range parsing error |
| 10 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 11 | pub enum HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError# { |
| 12 | /// Returned if range is invalid. |
| 13 | InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#, |
| 14 | /// Returned if first-byte-pos of all of the byte-range-spec |
| 15 | /// values is greater than the content size. |
| 16 | /// See https://github.com/golang/go/commit/aa9b3d7 |
| 17 | NoOverlaprust-analyzer cargo http-range 0.1.5 HttpRangeParseError#NoOverlap#, |
| 18 | } |
| 19 | |
| 20 | /// HTTP Range header representation. |
| 21 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 22 | pub struct HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 23 | pub startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: u64, |
| 24 | pub lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: u64, |
| 25 | } |
| 26 | |
| 27 | impl HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 28 | /// Parses Range HTTP header string as per RFC 2616. |
| 29 | /// |
| 30 | /// `header` is HTTP Range header (e.g. `bytes=bytes=0-9`). |
| 31 | /// `size` is full size of response (file). |
| 32 | pub fn parserust-analyzer cargo http-range 0.1.5 impl#[HttpRange]parse().(header: &str, size: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange#>, HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#> { |
| 33 | Selfrust-analyzer cargo http-range 0.1.5 impl#[HttpRange]::parse_bytesrust-analyzer cargo http-range 0.1.5 impl#[HttpRange]parse_bytes().(header.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), size) |
| 34 | } |
| 35 | |
| 36 | pub fn parse_bytesrust-analyzer cargo http-range 0.1.5 impl#[HttpRange]parse_bytes().(header: &[u8], size: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange#>, HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#> { |
| 37 | if header.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 38 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()); |
| 39 | } |
| 40 | |
| 41 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().header.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(PREFIXrust-analyzer cargo http-range 0.1.5 PREFIX.) { |
| 42 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#); |
| 43 | } |
| 44 | |
| 45 | let mut no_overlap = false; |
| 46 | |
| 47 | let ranges: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange#> = header[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().PREFIX_LENrust-analyzer cargo http-range 0.1.5 PREFIX_LEN...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 48 | .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split().(|b| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b',') |
| 49 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|ra| { |
| 50 | let ra = ra.trimrust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]trim().(); |
| 51 | if ra.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 52 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 53 | } |
| 54 | match Selfrust-analyzer cargo http-range 0.1.5 impl#[HttpRange]::parse_single_rangerust-analyzer cargo http-range 0.1.5 impl#[HttpRange]parse_single_range().(ra, size) { |
| 55 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(range)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(range)), |
| 56 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => { |
| 57 | no_overlap = true; |
| 58 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 59 | } |
| 60 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)), |
| 61 | } |
| 62 | }) |
| 63 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<_, _>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 64 | |
| 65 | if no_overlap && ranges.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 66 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::NoOverlaprust-analyzer cargo http-range 0.1.5 HttpRangeParseError#NoOverlap#); |
| 67 | } |
| 68 | |
| 69 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ranges) |
| 70 | } |
| 71 | |
| 72 | fn parse_single_rangerust-analyzer cargo http-range 0.1.5 impl#[HttpRange]parse_single_range().( |
| 73 | bytes: &[u8], |
| 74 | size: u64, |
| 75 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange#>, HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#> { |
| 76 | let mut start_end_iter = bytes.splitnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]splitn().(2, |b| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'-'); |
| 77 | |
| 78 | let start_str = start_end_iter |
| 79 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`SplitN<'a, T, P>`][Iterator]next().() |
| 80 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 81 | .trimrust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]trim().(); |
| 82 | let end_str = start_end_iter |
| 83 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`SplitN<'a, T, P>`][Iterator]next().() |
| 84 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 85 | .trimrust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]trim().(); |
| 86 | |
| 87 | if start_str.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 88 | // If no start is specified, end specifies the |
| 89 | // range start relative to the end of the file, |
| 90 | // and we are dealing with <suffix-length> |
| 91 | // which has to be a non-negative integer as per |
| 92 | // RFC 7233 Section 2.1 "Byte-Ranges". |
| 93 | if end_str.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() || end_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'-' { |
| 94 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#); |
| 95 | } |
| 96 | |
| 97 | let mut length: u64 = end_str |
| 98 | .parse_u64rust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]parse_u64().() |
| 99 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 100 | |
| 101 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 { |
| 102 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 103 | } |
| 104 | |
| 105 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().size { |
| 106 | length = size; |
| 107 | } |
| 108 | |
| 109 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 110 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: (size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().length), |
| 111 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length., |
| 112 | })) |
| 113 | } else { |
| 114 | let start: u64 = start_str |
| 115 | .parse_u64rust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]parse_u64().() |
| 116 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 117 | |
| 118 | if start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().size { |
| 119 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 120 | } |
| 121 | |
| 122 | let length = if end_str.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 123 | // If no end is specified, range extends to end of the file. |
| 124 | size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().start |
| 125 | } else { |
| 126 | let mut end: u64 = end_str |
| 127 | .parse_u64rust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]parse_u64().() |
| 128 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 129 | |
| 130 | if start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().end { |
| 131 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(HttpRangeParseErrorrust-analyzer cargo http-range 0.1.5 HttpRangeParseError#::InvalidRangerust-analyzer cargo http-range 0.1.5 HttpRangeParseError#InvalidRange#); |
| 132 | } |
| 133 | |
| 134 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().size { |
| 135 | end = size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().1; |
| 136 | } |
| 137 | |
| 138 | end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1 |
| 139 | }; |
| 140 | |
| 141 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { startrust-analyzer cargo http-range 0.1.5 HttpRange#start., lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length. })) |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | trait SliceExtrust-analyzer cargo http-range 0.1.5 SliceExt# { |
| 147 | fn trimrust-analyzer cargo http-range 0.1.5 SliceExt#trim().(&self) -> &Self; |
| 148 | fn parse_u64rust-analyzer cargo http-range 0.1.5 SliceExt#parse_u64().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u64, ()>; |
| 149 | } |
| 150 | |
| 151 | impl SliceExtrust-analyzer cargo http-range 0.1.5 SliceExt# for [u8] { |
| 152 | fn trimrust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]trim().(&self) -> &[u8] { |
| 153 | fn is_whitespacerust-analyzer cargo http-range 0.1.5 is_whitespace().(c: &u8) -> bool { |
| 154 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\t' || *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b' ' |
| 155 | } |
| 156 | |
| 157 | fn is_not_whitespacerust-analyzer cargo http-range 0.1.5 is_not_whitespace().(c: &u8) -> bool { |
| 158 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_whitespacerust-analyzer cargo http-range 0.1.5 is_whitespace().(c) |
| 159 | } |
| 160 | |
| 161 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first) = self.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(is_not_whitespacerust-analyzer cargo http-range 0.1.5 is_not_whitespace().) { |
| 162 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last) = self.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().rpositionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]rposition().(is_not_whitespacerust-analyzer cargo http-range 0.1.5 is_not_whitespace().) { |
| 163 | &self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().first..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#last rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 164 | } else { |
| 165 | unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(); |
| 166 | } |
| 167 | } else { |
| 168 | &[] |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | fn parse_u64rust-analyzer cargo http-range 0.1.5 impl#[`[u8]`][SliceExt]parse_u64().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u64, ()> { |
| 173 | if self.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 174 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(()); |
| 175 | } |
| 176 | let mut res = 0u64; |
| 177 | for b in self { |
| 178 | if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().b'0' && *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().b'9' { |
| 179 | res = res |
| 180 | .checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_mul().(10) |
| 181 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 182 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_add().((b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&u8`][`Sub<u8>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&u8`][`Sub<u8>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&u8`][`Sub<u8>`]sub().b'0') as u64) |
| 183 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 184 | } else { |
| 185 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(()); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | #[cfg(test)] |
| 194 | mod testsrust-analyzer cargo http-range 0.1.5 tests/ { |
| 195 | use superrust-analyzer cargo http-range 0.1.5 crate/::*; |
| 196 | |
| 197 | struct Trust-analyzer cargo http-range 0.1.5 tests/T#(&'static str, u64, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange#>); |
| 198 | |
| 199 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 200 | fn test_parserust-analyzer cargo http-range 0.1.5 tests/test_parse().() { |
| 201 | let tests = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 202 | Trust-analyzer cargo http-range 0.1.5 tests/T#("", 0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 203 | Trust-analyzer cargo http-range 0.1.5 tests/T#("", 1000, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 204 | Trust-analyzer cargo http-range 0.1.5 tests/T#("foo", 0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 205 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=", 0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 206 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=", 200, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 207 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=7", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 208 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes= 7 ", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 209 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=1-", 0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 210 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=5-4", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 211 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=--6", 200, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 212 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=--0", 200, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 213 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=---0", 200, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 214 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 215 | "bytes=-6", |
| 216 | 200, |
| 217 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 218 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 194, |
| 219 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 6, |
| 220 | }], |
| 221 | ), |
| 222 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 223 | "bytes=6-", |
| 224 | 200, |
| 225 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 226 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 6, |
| 227 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 194, |
| 228 | }], |
| 229 | ), |
| 230 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=-6-", 0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 231 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=-0", 200, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 232 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=0-2,5-4", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 233 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=2-5,4-3", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 234 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=--5,4--3", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 235 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=A-", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 236 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=A- ", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 237 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=A-Z", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 238 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes= -Z", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 239 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=5-Z", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 240 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=Ran-dom, garbage", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 241 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=0x01-0x02", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 242 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes= ", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 243 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes= , , , ", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 244 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 245 | "bytes=0-9", |
| 246 | 10, |
| 247 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 248 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 249 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 10, |
| 250 | }], |
| 251 | ), |
| 252 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 253 | "bytes=0-", |
| 254 | 10, |
| 255 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 256 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 257 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 10, |
| 258 | }], |
| 259 | ), |
| 260 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 261 | "bytes=5-", |
| 262 | 10, |
| 263 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 264 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 5, |
| 265 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 5, |
| 266 | }], |
| 267 | ), |
| 268 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 269 | "bytes=0-20", |
| 270 | 10, |
| 271 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 272 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 273 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 10, |
| 274 | }], |
| 275 | ), |
| 276 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 277 | "bytes=15-,0-5", |
| 278 | 10, |
| 279 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 280 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 281 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 6, |
| 282 | }], |
| 283 | ), |
| 284 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 285 | "bytes=1-2,5-", |
| 286 | 10, |
| 287 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 288 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 289 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 1, |
| 290 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 2, |
| 291 | }, |
| 292 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 293 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 5, |
| 294 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 5, |
| 295 | }, |
| 296 | ], |
| 297 | ), |
| 298 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 299 | "bytes=-2 , 7-", |
| 300 | 11, |
| 301 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 302 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 303 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 9, |
| 304 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 2, |
| 305 | }, |
| 306 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 307 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 7, |
| 308 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 4, |
| 309 | }, |
| 310 | ], |
| 311 | ), |
| 312 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 313 | "bytes=0-0 ,2-2, 7-", |
| 314 | 11, |
| 315 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 316 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 317 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 318 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 1, |
| 319 | }, |
| 320 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 321 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 2, |
| 322 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 1, |
| 323 | }, |
| 324 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 325 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 7, |
| 326 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 4, |
| 327 | }, |
| 328 | ], |
| 329 | ), |
| 330 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 331 | "bytes=-5", |
| 332 | 10, |
| 333 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 334 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 5, |
| 335 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 5, |
| 336 | }], |
| 337 | ), |
| 338 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 339 | "bytes=-15", |
| 340 | 10, |
| 341 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 342 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 343 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 10, |
| 344 | }], |
| 345 | ), |
| 346 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 347 | "bytes=0-499", |
| 348 | 10000, |
| 349 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 350 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 351 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 500, |
| 352 | }], |
| 353 | ), |
| 354 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 355 | "bytes=500-999", |
| 356 | 10000, |
| 357 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 358 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 500, |
| 359 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 500, |
| 360 | }], |
| 361 | ), |
| 362 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 363 | "bytes=-500", |
| 364 | 10000, |
| 365 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 366 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 9500, |
| 367 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 500, |
| 368 | }], |
| 369 | ), |
| 370 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 371 | "bytes=9500-", |
| 372 | 10000, |
| 373 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 374 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 9500, |
| 375 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 500, |
| 376 | }], |
| 377 | ), |
| 378 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 379 | "bytes=0-0,-1", |
| 380 | 10000, |
| 381 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 382 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 383 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 384 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 1, |
| 385 | }, |
| 386 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 387 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 9999, |
| 388 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 1, |
| 389 | }, |
| 390 | ], |
| 391 | ), |
| 392 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 393 | "bytes=500-600,601-999", |
| 394 | 10000, |
| 395 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 396 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 397 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 500, |
| 398 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 101, |
| 399 | }, |
| 400 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 401 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 601, |
| 402 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 399, |
| 403 | }, |
| 404 | ], |
| 405 | ), |
| 406 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 407 | "bytes=500-700,601-999", |
| 408 | 10000, |
| 409 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 410 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 411 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 500, |
| 412 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 201, |
| 413 | }, |
| 414 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 415 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 601, |
| 416 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 399, |
| 417 | }, |
| 418 | ], |
| 419 | ), |
| 420 | // Match Apache laxity: |
| 421 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 422 | "bytes= 1 -2 , 4- 5, 7 - 8 , ,,", |
| 423 | 11, |
| 424 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 425 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 426 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 1, |
| 427 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 2, |
| 428 | }, |
| 429 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 430 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 4, |
| 431 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 2, |
| 432 | }, |
| 433 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 434 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 7, |
| 435 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 2, |
| 436 | }, |
| 437 | ], |
| 438 | ), |
| 439 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 440 | "bytes=50-60,2-3", |
| 441 | 10, |
| 442 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 443 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 2, |
| 444 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 2, |
| 445 | }], |
| 446 | ), |
| 447 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 448 | "bytes=50-60,-5", |
| 449 | 10, |
| 450 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 451 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 5, |
| 452 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 5, |
| 453 | }], |
| 454 | ), |
| 455 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 456 | "bytes=50-60,7-", |
| 457 | 10, |
| 458 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 459 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 7, |
| 460 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 3, |
| 461 | }], |
| 462 | ), |
| 463 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=50-60,20-", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 464 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 465 | "bytes=50-60,20-,3-4", |
| 466 | 10, |
| 467 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 468 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 3, |
| 469 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 2, |
| 470 | }], |
| 471 | ), |
| 472 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 473 | "bytes=9-20,-5", |
| 474 | 10, |
| 475 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 476 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 477 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 9, |
| 478 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 1, |
| 479 | }, |
| 480 | HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 481 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 5, |
| 482 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 5, |
| 483 | }, |
| 484 | ], |
| 485 | ), |
| 486 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=15-20,-0", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 487 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 488 | "bytes=15-20,-0", |
| 489 | 20, |
| 490 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 491 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 15, |
| 492 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 5, |
| 493 | }], |
| 494 | ), |
| 495 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=1-2,bytes=3-4", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 496 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=1-2,blergh=3-4", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 497 | Trust-analyzer cargo http-range 0.1.5 tests/T#("blergh=1-2,bytes=3-4", 10, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 498 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=-0", 0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 499 | Trust-analyzer cargo http-range 0.1.5 tests/T#("bytes=-0", 5, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 500 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 501 | "bytes=-1", |
| 502 | 0, |
| 503 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange# { |
| 504 | startrust-analyzer cargo http-range 0.1.5 HttpRange#start.: 0, |
| 505 | lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length.: 0, |
| 506 | }], |
| 507 | ), |
| 508 | Trust-analyzer cargo http-range 0.1.5 tests/T#( |
| 509 | "bytes=0-99999999999999999999999999999999999999999999", |
| 510 | 10, |
| 511 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 512 | ), |
| 513 | ]; |
| 514 | |
| 515 | for t in tests { |
| 516 | let header = t.0rust-analyzer cargo http-range 0.1.5 tests/T#0.; |
| 517 | let size = t.1rust-analyzer cargo http-range 0.1.5 tests/T#1.; |
| 518 | let expected = t.2rust-analyzer cargo http-range 0.1.5 tests/T#2.; |
| 519 | |
| 520 | let res = HttpRangerust-analyzer cargo http-range 0.1.5 HttpRange#::parserust-analyzer cargo http-range 0.1.5 impl#[HttpRange]parse().(header, size); |
| 521 | |
| 522 | if res.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 523 | if expected.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 524 | continue; |
| 525 | } else { |
| 526 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 527 | false, |
| 528 | "parse({}, {}) returned error {:?}", |
| 529 | header, |
| 530 | size, |
| 531 | res.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().() |
| 532 | ); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | let got = res.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 537 | |
| 538 | if got.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().expected.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 539 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 540 | false, |
| 541 | "len(parseRange({}, {})) = {}, want {}", |
| 542 | header, |
| 543 | size, |
| 544 | got.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 545 | expected.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 546 | ); |
| 547 | continue; |
| 548 | } |
| 549 | |
| 550 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#expected.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 551 | if got[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..startrust-analyzer cargo http-range 0.1.5 HttpRange#start. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().expected[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..startrust-analyzer cargo http-range 0.1.5 HttpRange#start. { |
| 552 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 553 | false, |
| 554 | "parseRange({}, {})[{}].start = {}, want {}", |
| 555 | header, size, i, got[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..startrust-analyzer cargo http-range 0.1.5 HttpRange#start., expected[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..startrust-analyzer cargo http-range 0.1.5 HttpRange#start. |
| 556 | ) |
| 557 | } |
| 558 | if got[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().expected[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length. { |
| 559 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 560 | false, |
| 561 | "parseRange({}, {})[{}].length = {}, want {}", |
| 562 | header, size, i, got[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length., expected[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..lengthrust-analyzer cargo http-range 0.1.5 HttpRange#length. |
| 563 | ) |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | } |