Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 #![doc = include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("../README.md")]
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
4
5 use craterust-analyzer cargo http-content-range 0.2.5 crate/::utilsrust-analyzer cargo http-content-range 0.2.5 utils/::{fail_ifrust-analyzer cargo http-content-range 0.2.5 utils/fail_if()., is_whitespacerust-analyzer cargo http-content-range 0.2.5 utils/is_whitespace()., IterExtrust-analyzer cargo http-content-range 0.2.5 utils/IterExt#};
6
7 mod utilsrust-analyzer cargo http-content-range 0.2.5 utils/;
8
9 const PREFIXrust-analyzer cargo http-content-range 0.2.5 PREFIX.: &[u8] = b"bytes";
10
11 /// HTTP Content-Range response header representation.
12 #[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:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
13 pub enum ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange# {
14 /// Regular bytes range response with status 206
15 Bytesrust-analyzer cargo http-content-range 0.2.5 ContentRange#Bytes#(ContentRangeBytesrust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#),
16 /// Regular bytes range response with status 206
17 UnboundBytesrust-analyzer cargo http-content-range 0.2.5 ContentRange#UnboundBytes#(ContentRangeUnboundrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound#),
18 /// Server response with status 416
19 Unsatisfiedrust-analyzer cargo http-content-range 0.2.5 ContentRange#Unsatisfied#(ContentRangeUnsatisfiedrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnsatisfied#),
20 }
21
22 #[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:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
23 pub struct ContentRangeBytesrust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes# {
24 pub first_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#first_byte.: u64,
25 pub last_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#last_byte.: u64,
26 pub complete_lengthrust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#complete_length.: u64,
27 }
28
29 #[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:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
30 pub struct ContentRangeUnboundrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound# {
31 pub first_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound#first_byte.: u64,
32 pub last_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound#last_byte.: u64,
33 }
34
35 #[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:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
36 pub struct ContentRangeUnsatisfiedrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnsatisfied# {
37 pub complete_lengthrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnsatisfied#complete_length.: u64,
38 }
39
40 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&str> for ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange# {
41 type Errorrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&str>`]Error# = ();
42
43 fn try_fromrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&str>`]try_from().(value: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&str>`], Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&str>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> {
44 Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&str>`]::parserust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange]parse().(value).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(())
45 }
46 }
47
48 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&[u8]> for ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange# {
49 type Errorrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&[u8]>`]Error# = ();
50
51 fn try_fromrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&[u8]>`]try_from().(value: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&[u8]>`], Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&[u8]>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> {
52 Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&[u8]>`]::parse_bytesrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange]parse_bytes().(value).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(())
53 }
54 }
55
56 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange# {
57 type Errrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][FromStr]Err# = ();
58
59 fn from_strrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][FromStr], Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
60 Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][FromStr]::try_fromrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&str>`]try_from().(s)
61 }
62 }
63
64 impl ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange# {
65 /// Parses Content-Range HTTP header string as per
66 /// [RFC 7233](https://httpwg.org/specs/rfc7233.html#header.content-range).
67 ///
68 /// `header` is the HTTP Content-Range header (e.g. `bytes 0-9/30`).
69 ///
70 /// This parser is a bit more lenient than the official RFC, it allows spaces and tabs between everything.
71 /// See <https://httpwg.org/specs/rfc7233.html#rfc.section.4.2>
72 ///
73 /// ```
74 /// # use http_content_range::{ContentRange, ContentRangeBytes, ContentRangeUnbound, ContentRangeUnsatisfied};
75 /// assert_eq!(ContentRange::parse("bytes 42-69/420").unwrap(),
76 /// ContentRange::Bytes(ContentRangeBytes{first_byte: 42, last_byte: 69, complete_length: 420}));
77 ///
78 /// // complete_length is unknown
79 /// assert_eq!(ContentRange::parse("bytes 42-69/*").unwrap(),
80 /// ContentRange::UnboundBytes(ContentRangeUnbound{first_byte: 42, last_byte: 69}));
81 ///
82 /// // response is unsatisfied
83 /// assert_eq!(ContentRange::parse("bytes */420").unwrap(),
84 /// ContentRange::Unsatisfied(ContentRangeUnsatisfied{complete_length: 420}));
85 /// ```
86 #[must_use]
87 #[inline]
88 pub fn parserust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange]parse().(header: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#> {
89 Selfrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange]::parse_bytesrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange]parse_bytes().(header.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
90 }
91
92 /// From <https://httpwg.org/specs/rfc7233.html#rfc.section.4.2>
93 /// Valid bytes responses:
94 /// Content-Range: bytes 42-1233/1234
95 /// Content-Range: bytes 42-1233/*
96 /// Content-Range: bytes */1233
97 ///
98 /// ```none
99 /// Content-Range = byte-content-range
100 /// / other-content-range
101 ///
102 /// byte-content-range = bytes-unit SP
103 /// ( byte-range-resp / unsatisfied-range )
104 ///
105 /// byte-range-resp = byte-range "/" ( complete-length / "*" )
106 /// byte-range = first-byte-pos "-" last-byte-pos
107 /// unsatisfied-range = "*/" complete-length
108 ///
109 /// complete-length = 1*DIGIT
110 ///
111 /// other-content-range = other-range-unit SP other-range-resp
112 /// other-range-resp = *CHAR
113 /// ```
114 /// Same as [`parse`](Self::parse) but parses directly from the byte array
115 #[must_use]
116 pub fn parse_bytesrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange]parse_bytes().(header: &[u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#> {
117 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-content-range 0.2.5 PREFIX.) {
118 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
119 }
120
121 let mut iter = header[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().PREFIXrust-analyzer cargo http-content-range 0.2.5 PREFIX..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]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()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
122
123 // must start with a space
124 fail_ifrust-analyzer cargo http-content-range 0.2.5 utils/fail_if().(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_whitespacerust-analyzer cargo http-content-range 0.2.5 utils/is_whitespace().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
125 let res = if iter.skip_spacesrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]skip_spaces().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). 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'*' {
126 // Unsatisfied range
127 iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; // consume '*'
128 iter.parse_separatorrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_separator().(b'/')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
129 ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::Unsatisfiedrust-analyzer cargo http-content-range 0.2.5 ContentRange#Unsatisfied#(ContentRangeUnsatisfiedrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnsatisfied# {
130 complete_lengthrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnsatisfied#complete_length.: iter.parse_u64rust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().,
131 })
132 } else {
133 // byte range
134 let first_byte = iter.parse_u64rust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
135 iter.parse_separatorrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_separator().(b'-')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
136 let last_byte = iter.parse_u64rust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
137 fail_ifrust-analyzer cargo http-content-range 0.2.5 utils/fail_if().(first_byte 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().last_byte)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
138 if iter.parse_separatorrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_separator().(b'/')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). 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'*' {
139 // unbound byte range, consume '*'
140 iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
141 ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::UnboundBytesrust-analyzer cargo http-content-range 0.2.5 ContentRange#UnboundBytes#(ContentRangeUnboundrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound# {
142 first_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound#first_byte.,
143 last_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound#last_byte.,
144 })
145 } else {
146 let complete_length = iter.parse_u64rust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
147 fail_ifrust-analyzer cargo http-content-range 0.2.5 utils/fail_if().(last_byte 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().complete_length)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
148 ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::Bytesrust-analyzer cargo http-content-range 0.2.5 ContentRange#Bytes#(ContentRangeBytesrust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes# {
149 first_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#first_byte.,
150 last_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#last_byte.,
151 complete_lengthrust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#complete_length.,
152 })
153 }
154 };
155
156 // verify there is nothing left
157 match iter.skip_spacesrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]skip_spaces().() {
158 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(res),
159 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
160 }
161 }
162 }
163
164 #[cfg(test)]
165 mod testsrust-analyzer cargo http-content-range 0.2.5 tests/ {
166 #![allow(clippy::unnecessary_wraps)]
167
168 use superrust-analyzer cargo http-content-range 0.2.5 crate/::*;
169
170 fn bytesrust-analyzer cargo http-content-range 0.2.5 tests/bytes().(first_byte: u64, last_byte: u64, complete_length: u64) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#> {
171 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::Bytesrust-analyzer cargo http-content-range 0.2.5 ContentRange#Bytes#(ContentRangeBytesrust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes# {
172 first_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#first_byte.,
173 last_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#last_byte.,
174 complete_lengthrust-analyzer cargo http-content-range 0.2.5 ContentRangeBytes#complete_length.,
175 }))
176 }
177
178 fn unboundrust-analyzer cargo http-content-range 0.2.5 tests/unbound().(first_byte: u64, last_byte: u64) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#> {
179 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::UnboundBytesrust-analyzer cargo http-content-range 0.2.5 ContentRange#UnboundBytes#(ContentRangeUnboundrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound# {
180 first_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound#first_byte.,
181 last_byterust-analyzer cargo http-content-range 0.2.5 ContentRangeUnbound#last_byte.,
182 }))
183 }
184
185 fn unsatisfiedrust-analyzer cargo http-content-range 0.2.5 tests/unsatisfied().(complete_length: u64) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#> {
186 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::Unsatisfiedrust-analyzer cargo http-content-range 0.2.5 ContentRange#Unsatisfied#(ContentRangeUnsatisfiedrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnsatisfied# {
187 complete_lengthrust-analyzer cargo http-content-range 0.2.5 ContentRangeUnsatisfied#complete_length.,
188 }))
189 }
190
191 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
192 fn test_parserust-analyzer cargo http-content-range 0.2.5 tests/test_parse().() {
193 for (header, expected) in vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
194 // Valid
195 ("bytes 0-9/20", bytesrust-analyzer cargo http-content-range 0.2.5 tests/bytes().(0, 9, 20)),
196 ("bytes\t 0 \t -\t \t \t9 / 20 ", bytesrust-analyzer cargo http-content-range 0.2.5 tests/bytes().(0, 9, 20)),
197 ("bytes */20", unsatisfiedrust-analyzer cargo http-content-range 0.2.5 tests/unsatisfied().(20)),
198 ("bytes *\t\t/ 20 ", unsatisfiedrust-analyzer cargo http-content-range 0.2.5 tests/unsatisfied().(20)),
199 ("bytes 0-9/*", unboundrust-analyzer cargo http-content-range 0.2.5 tests/unbound().(0, 9)),
200 ("bytes 0 - 9 / * ", unboundrust-analyzer cargo http-content-range 0.2.5 tests/unbound().(0, 9)),
201 //
202 // Errors
203 //
204 ("", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
205 ("b", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
206 ("foo", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
207 ("foo 1-2/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
208 (" bytes 1-2/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
209 ("bytes -2/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
210 ("bytes 1-/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
211 ("bytes 1-2/", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
212 ("bytes 1-2/a", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
213 ("bytes1-2/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
214 ("bytes=1-2/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
215 ("bytes a-2/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
216 ("bytes 1-a/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
217 ("bytes 0x01-0x02/3", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
218 ("bytes 1-2/a", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
219 (
220 "bytes 1111111111111111111111111111111111111111111-2/1",
221 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
222 ),
223 ("bytes 1-3/20 1", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
224 ("bytes 1-3/* 1", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
225 ("bytes */1 1", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
226 ("bytes 1-0/20", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
227 ("bytes 1-20/20", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
228 ("bytes 1-21/20", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
229 ] {
230 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::parserust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange]parse().(header), expected);
231 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::try_fromrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&str>`]try_from().(header).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(), expected);
232 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::from_strrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][FromStr]from_str().(header).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(), expected);
233 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ContentRangerust-analyzer cargo http-content-range 0.2.5 ContentRange#::try_fromrust-analyzer cargo http-content-range 0.2.5 impl#[ContentRange][`TryFrom<&[u8]>`]try_from().(header.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(), expected);
234 }
235 }
236 }