Debian Codegraph @

src/utils.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#;
3
4 /// Helper method that returns None if test is true
5 #[inline]
6 #[must_use]
7 pub fn fail_ifrust-analyzer cargo http-content-range 0.2.5 utils/fail_if().(test: bool) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<()> {
8 if test {
9 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
10 } else {
11 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(())
12 }
13 }
14
15 #[inline]
16 pub fn is_whitespacerust-analyzer cargo http-content-range 0.2.5 utils/is_whitespace().(c: u8) -> bool {
17 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' || 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' '
18 }
19
20 #[inline]
21 fn into_digitrust-analyzer cargo http-content-range 0.2.5 utils/into_digit().(c: u8) -> u64 {
22 u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().b'0')
23 }
24
25 pub(craterust-analyzer cargo http-content-range 0.2.5 crate/) trait IterExtrust-analyzer cargo http-content-range 0.2.5 utils/IterExt# {
26 #[must_use]
27 fn skip_spacesrust-analyzer cargo http-content-range 0.2.5 utils/IterExt#skip_spaces().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>;
28 #[must_use]
29 fn parse_separatorrust-analyzer cargo http-content-range 0.2.5 utils/IterExt#parse_separator().(&mut self, separator: u8) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>;
30 #[must_use]
31 fn parse_u64rust-analyzer cargo http-content-range 0.2.5 utils/IterExt#parse_u64().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>;
32 }
33
34 impl IterExtrust-analyzer cargo http-content-range 0.2.5 utils/IterExt# for Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'_, u8>> {
35 /// Advances to the next non-blank byte, returning true if there is more data
36 fn skip_spacesrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]skip_spaces().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8> {
37 loop {
38 match self.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
39 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
40 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => {
41 if 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().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v) {
42 self.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
43 } else {
44 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v);
45 }
46 }
47 }
48 }
49 }
50
51 /// Skip spaces, and ensure there is a given separator. Returns next non-space value
52 fn parse_separatorrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_separator().(&mut self, separator: u8) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8> {
53 if self.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>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().separator {
54 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
55 }
56 self.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 separator
57 self.skip_spacesrust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]skip_spaces().()
58 }
59
60 /// Consume u64 value
61 fn parse_u64rust-analyzer cargo http-content-range 0.2.5 utils/impl#[`Peekable<Iter<'_, u8>>`][IterExt]parse_u64().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64> {
62 let mut res = match self.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
63 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
64 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => {
65 let c = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v;
66 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_digit().() {
67 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
68 }
69 into_digitrust-analyzer cargo http-content-range 0.2.5 utils/into_digit().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v)
70 }
71 };
72 loop {
73 match self.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
74 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(res),
75 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => {
76 let next = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v;
77 if next.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_digit().() {
78 res = res.checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_mul().(10)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_add().(into_digitrust-analyzer cargo http-content-range 0.2.5 utils/into_digit().(next))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
79 self.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
80 } else {
81 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(res);
82 }
83 }
84 }
85 }
86 }
87 }