Debian Codegraph @

src/utils.rs

raw symbols SCIP
1 #[cfg(feature = "std")]
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#;
3
4 use craterust-analyzer cargo qoi 0.4.1 crate/::errorrust-analyzer cargo qoi 0.4.1 error/::Resultrust-analyzer cargo qoi 0.4.1 error/Result#;
5
6 #[inline(always)]
7 #[cold]
8 pub const fn coldrust-analyzer cargo qoi 0.4.1 utils/cold().() {}
9
10 #[inline(always)]
11 #[allow(unused)]
12 pub const fn likelyrust-analyzer cargo qoi 0.4.1 utils/likely().(b: bool) -> bool {
13 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().b {
14 coldrust-analyzer cargo qoi 0.4.1 utils/cold().();
15 }
16 b
17 }
18
19 #[inline(always)]
20 pub const fn unlikelyrust-analyzer cargo qoi 0.4.1 utils/unlikely().(b: bool) -> bool {
21 if b {
22 coldrust-analyzer cargo qoi 0.4.1 utils/cold().();
23 }
24 b
25 }
26
27 pub trait Writerrust-analyzer cargo qoi 0.4.1 utils/Writer#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
28 fn write_onerust-analyzer cargo qoi 0.4.1 utils/Writer#write_one().(self, v: u8) -> Resultrust-analyzer cargo qoi 0.4.1 error/Result#<Self>;
29 fn write_manyrust-analyzer cargo qoi 0.4.1 utils/Writer#write_many().(self, v: &[u8]) -> Resultrust-analyzer cargo qoi 0.4.1 error/Result#<Self>;
30 fn capacityrust-analyzer cargo qoi 0.4.1 utils/Writer#capacity().(&self) -> usize;
31 }
32
33 pub struct BytesMutrust-analyzer cargo qoi 0.4.1 utils/BytesMut#<'a>(&'a mut [u8]);
34
35 impl<'a> BytesMutrust-analyzer cargo qoi 0.4.1 utils/BytesMut#<'a> {
36 pub fn newrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`]new().(buf: &'a mut [u8]) -> Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`] {
37 Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`](buf)
38 }
39
40 #[inline]
41 pub fn write_onerust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`]write_one().(self, v: u8) -> Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`] {
42 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((first, tail)) = self.0rust-analyzer cargo qoi 0.4.1 utils/BytesMut#0..split_first_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_first_mut().() {
43 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().first = v;
44 Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`](tail)
45 } else {
46 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!()
47 }
48 }
49
50 #[inline]
51 pub fn write_manyrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`]write_many().(self, v: &[u8]) -> Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`] {
52 if v.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 cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().self.0rust-analyzer cargo qoi 0.4.1 utils/BytesMut#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
53 let (head, tail) = self.0rust-analyzer cargo qoi 0.4.1 utils/BytesMut#0..split_at_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at_mut().(v.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
54 head.copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(v);
55 Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`](tail)
56 } else {
57 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!()
58 }
59 }
60 }
61
62 impl<'a> Writerrust-analyzer cargo qoi 0.4.1 utils/Writer# for BytesMutrust-analyzer cargo qoi 0.4.1 utils/BytesMut#<'a> {
63 #[inline]
64 fn write_onerust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`][Writer]write_one().(self, v: u8) -> Resultrust-analyzer cargo qoi 0.4.1 error/Result#<Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`][Writer]> {
65 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BytesMutrust-analyzer cargo qoi 0.4.1 utils/BytesMut#::write_onerust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`]write_one().(self, v))
66 }
67
68 #[inline]
69 fn write_manyrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`][Writer]write_many().(self, v: &[u8]) -> Resultrust-analyzer cargo qoi 0.4.1 error/Result#<Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`][Writer]> {
70 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BytesMutrust-analyzer cargo qoi 0.4.1 utils/BytesMut#::write_manyrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`]write_many().(self, v))
71 }
72
73 #[inline]
74 fn capacityrust-analyzer cargo qoi 0.4.1 utils/impl#[`BytesMut<'a>`][Writer]capacity().(&self) -> usize {
75 self.0rust-analyzer cargo qoi 0.4.1 utils/BytesMut#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()
76 }
77 }
78
79 #[cfg(feature = "std")]
80 pub struct GenericWriterrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#<W> {
81 writerrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#writer.: W,
82 n_writtenrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#n_written.: usize,
83 }
84
85 #[cfg(feature = "std")]
86 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> GenericWriterrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#<W> {
87 pub const fn newrust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`]new().(writer: W) -> Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`] {
88 Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`] { writerrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#writer., n_writtenrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#n_written.: 0 }
89 }
90 }
91
92 #[cfg(feature = "std")]
93 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Writerrust-analyzer cargo qoi 0.4.1 utils/Writer# for GenericWriterrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#<W> {
94 fn write_onerust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`][Writer]write_one().(mut self, v: u8) -> Resultrust-analyzer cargo qoi 0.4.1 error/Result#<Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`][Writer]> {
95 self.n_writtenrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#n_written. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
96 self.writerrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#writer..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&[v]).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|_| self).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
97 }
98
99 fn write_manyrust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`][Writer]write_many().(mut self, v: &[u8]) -> Resultrust-analyzer cargo qoi 0.4.1 error/Result#<Selfrust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`][Writer]> {
100 self.n_writtenrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#n_written. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().v.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
101 self.writerrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#writer..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(v).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|_| self).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
102 }
103
104 fn capacityrust-analyzer cargo qoi 0.4.1 utils/impl#[`GenericWriter<W>`][Writer]capacity().(&self) -> usize {
105 usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.n_writtenrust-analyzer cargo qoi 0.4.1 utils/GenericWriter#n_written.
106 }
107 }