| 1 | // vim: tw=80 |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 4 | borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::{Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#, BorrowMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/BorrowMut#}, |
| 5 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/, |
| 6 | convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#, |
| 7 | errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/, |
| 8 | fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#}, |
| 9 | hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/, |
| 10 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, |
| 11 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/, |
| 12 | opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/, |
| 13 | syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::{ |
| 14 | selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/, |
| 15 | AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#, |
| 16 | Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::{AcqRelrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#AcqRel#, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#, Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#, Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#}, |
| 17 | }, |
| 18 | }; |
| 19 | |
| 20 | #[cfg(target_pointer_width = "64")] |
| 21 | const WRITER_SHIFTrust-analyzer cargo divbuf 0.4.1 divbuf/WRITER_SHIFT.: usize = 32; |
| 22 | #[cfg(target_pointer_width = "64")] |
| 23 | const READER_MASKrust-analyzer cargo divbuf 0.4.1 divbuf/READER_MASK.: usize = 0xFFFF_FFFF; |
| 24 | #[cfg(target_pointer_width = "32")] |
| 25 | const WRITER_SHIFT: usize = 16; |
| 26 | #[cfg(target_pointer_width = "32")] |
| 27 | const READER_MASK: usize = 0xFFFF; |
| 28 | const ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER.: usize = 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<Self>`]shl().WRITER_SHIFTrust-analyzer cargo divbuf 0.4.1 divbuf/WRITER_SHIFT.; |
| 29 | |
| 30 | /// DivBuf's error type |
| 31 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 32 | pub struct Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#(&'static str); |
| 33 | |
| 34 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error# { |
| 35 | fn fmtrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[Error][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 36 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.0rust-analyzer cargo divbuf 0.4.1 divbuf/Error#0.) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | impl errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error# {} |
| 41 | |
| 42 | /// The return type of |
| 43 | /// [`DivBuf::into_chunks`](struct.DivBuf.html#method.into_chunks) |
| 44 | // LCOV_EXCL_START |
| 45 | #[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:)] |
| 46 | pub struct Chunksrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks# { |
| 47 | dbrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#db.: DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#, |
| 48 | chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#chunksize.: usize, |
| 49 | } |
| 50 | // LCOV_EXCL_STOP |
| 51 | |
| 52 | impl Chunksrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks# { |
| 53 | fn newrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[Chunks]new().(db: DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#, chunksize: usize) -> Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[Chunks] { |
| 54 | Chunksrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks# { dbrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#db., chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#chunksize. } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Chunksrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks# { |
| 59 | type Itemrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[Chunks][Iterator]Item# = DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#; |
| 60 | |
| 61 | fn nextrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[Chunks][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#> { |
| 62 | if self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#db..is_emptyrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]is_empty().() { |
| 63 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 64 | } else { |
| 65 | let size = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(self.chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#chunksize., self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#db..lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]len().()); |
| 66 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#db..split_torust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]split_to().(size)) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | fn size_hintrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[Chunks][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 71 | let mut c = self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#db..lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().self.chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#chunksize.; |
| 72 | if self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#db..lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().self.chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#chunksize. 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().0 { |
| 73 | c 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; |
| 74 | } |
| 75 | (c, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c)) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /// The return type of |
| 80 | /// [`DivBufMut::into_chunks`](struct.DivBufMut.html#method.into_chunks) |
| 81 | // LCOV_EXCL_START |
| 82 | #[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:)] |
| 83 | pub struct ChunksMutrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut# { |
| 84 | dbrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#db.: DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#, |
| 85 | chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#chunksize.: usize, |
| 86 | } |
| 87 | // LCOV_EXCL_STOP |
| 88 | |
| 89 | impl ChunksMutrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut# { |
| 90 | fn newrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[ChunksMut]new().(db: DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#, chunksize: usize) -> Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[ChunksMut] { |
| 91 | ChunksMutrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut# { dbrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#db., chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#chunksize. } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ChunksMutrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut# { |
| 96 | type Itemrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[ChunksMut][Iterator]Item# = DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#; |
| 97 | |
| 98 | fn nextrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[ChunksMut][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#> { |
| 99 | if self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#db..is_emptyrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_empty().() { |
| 100 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 101 | } else { |
| 102 | let size = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(self.chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#chunksize., self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#db..lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]len().()); |
| 103 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#db..split_torust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]split_to().(size)) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | fn size_hintrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[ChunksMut][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 108 | let mut c = self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#db..lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().self.chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#chunksize.; |
| 109 | if self.dbrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#db..lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().self.chunksizerust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#chunksize. 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().0 { |
| 110 | c 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; |
| 111 | } |
| 112 | (c, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c)) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // LCOV_EXCL_START |
| 117 | #[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:)] |
| 118 | struct Innerrust-analyzer cargo divbuf 0.4.1 divbuf/Inner# { |
| 119 | vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 120 | /// Stores the number of readers in the low half, and writers in the high |
| 121 | /// half. |
| 122 | accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#, |
| 123 | /// Stores the total number of DivBufShareds owning this Inner |
| 124 | sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#, |
| 125 | } |
| 126 | // LCOV_EXCL_STOP |
| 127 | |
| 128 | /// The "entry point" to the `divbuf` crate. |
| 129 | /// |
| 130 | /// A `DivBufShared` owns storage, but cannot directly access it. An |
| 131 | /// application will typically create an instance of this class for every |
| 132 | /// independent buffer it wants to manage, and then create child `DivBuf`s or |
| 133 | /// `DivBufMut`s to access the storage. |
| 134 | pub struct DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 135 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner.: *mut Innerrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#, |
| 136 | } |
| 137 | |
| 138 | /// Provides read-only access to a buffer. |
| 139 | /// |
| 140 | /// This struct provides a window into a region of a `DivBufShared`, allowing |
| 141 | /// read-only access. It can be divided into smaller `DivBuf` using the |
| 142 | /// [`split_to`], [`split_off`], [`slice`], [`slice_from`], and [`slice_to`] |
| 143 | /// methods. Adjacent `DivBuf`s can be combined using the [`unsplit`] method. |
| 144 | /// Finally, a `DivBuf` can be upgraded to a writable [`DivBufMut`] using the |
| 145 | /// [`try_mut`] method, but only if there are no other `DivBuf`s that reference |
| 146 | /// the same `DivBufShared`. |
| 147 | /// |
| 148 | /// # Examples |
| 149 | /// |
| 150 | /// ``` |
| 151 | /// # use divbuf::*; |
| 152 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 153 | /// let mut db0 : DivBuf = dbs.try_const().unwrap(); |
| 154 | /// assert_eq!(db0, [1, 2, 3, 4, 5, 6][..]); |
| 155 | /// ``` |
| 156 | /// |
| 157 | /// Unlike [`DivBufMut`], a `DivBuf` cannot be used to modify the buffer. The |
| 158 | /// following example will fail. |
| 159 | /// |
| 160 | /// ```compile_fail |
| 161 | /// # use divbuf::*; |
| 162 | /// let dbs = DivBufShared::from(vec![1, 2, 3]); |
| 163 | /// let mut db = dbs.try_const().unwrap(); |
| 164 | /// db[0] = 9; |
| 165 | /// ``` |
| 166 | /// |
| 167 | /// [`DivBufMut`]: struct.DivBufMut.html |
| 168 | /// [`slice_from`]: #method.slice_from |
| 169 | /// [`slice_to`]: #method.slice_to |
| 170 | /// [`slice`]: #method.slice |
| 171 | /// [`split_off`]: #method.split_off |
| 172 | /// [`split_to`]: #method.split_to |
| 173 | /// [`try_mut`]: #method.try_mut |
| 174 | /// [`unsplit`]: #method.unsplit |
| 175 | // LCOV_EXCL_START |
| 176 | #[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:)] |
| 177 | pub struct DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 178 | // inner must be *mut just to support the try_mut method |
| 179 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.: *mut Innerrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#, |
| 180 | // In the future, consider optimizing by replacing begin with a pointer |
| 181 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin.: usize, |
| 182 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.: usize, |
| 183 | } |
| 184 | // LCOV_EXCL_STOP |
| 185 | |
| 186 | /// Provides read-write access to a buffer |
| 187 | /// |
| 188 | /// This structure provides a window into a region of a `DivBufShared`, allowing |
| 189 | /// read-write access. It can be divided into smaller `DivBufMut` using the |
| 190 | /// [`split_to`], and [`split_off`] methods. Adjacent `DivBufMut`s can be |
| 191 | /// combined using the [`unsplit`] method. `DivBufMut` dereferences to a |
| 192 | /// `&[u8]`, which is usually the easiest way to access its contents. However, |
| 193 | /// it can also be modified using the `Vec`-like methods [`extend`], |
| 194 | /// [`try_extend`], [`reserve`], and [`try_truncate`]. Crucially, those methods |
| 195 | /// will only work for terminal `DivBufMut`s. That is, a `DivBufMut` whose |
| 196 | /// range includes the end of the `DivBufShared`'s buffer. |
| 197 | /// |
| 198 | /// `divbuf` includes a primitive form of range-locking. It's possible to have |
| 199 | /// multiple `DivBufMut`s simultaneously referencing a single `DivBufShared`, |
| 200 | /// but there's no way to create overlapping `DivBufMut`s. |
| 201 | /// |
| 202 | /// # Examples |
| 203 | /// |
| 204 | /// ``` |
| 205 | /// # use divbuf::*; |
| 206 | /// let dbs = DivBufShared::from(vec![0; 64]); |
| 207 | /// let mut dbm = dbs.try_mut().unwrap(); |
| 208 | /// dbm[0..4].copy_from_slice(&b"Blue"[..]); |
| 209 | /// ``` |
| 210 | /// |
| 211 | /// [`split_off`]: #method.split_off |
| 212 | /// [`split_to`]: #method.split_to |
| 213 | /// [`unsplit`]: #method.unsplit |
| 214 | /// [`extend`]: #method.extend |
| 215 | /// [`try_extend`]: #method.try_extend |
| 216 | /// [`reserve`]: #method.reserve |
| 217 | /// [`try_truncate`]: #method.try_truncate |
| 218 | // LCOV_EXCL_START |
| 219 | #[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:)] |
| 220 | pub struct DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 221 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.: *mut Innerrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#, |
| 222 | // In the future, consider optimizing by replacing begin with a pointer |
| 223 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin.: usize, |
| 224 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.: usize, |
| 225 | } |
| 226 | // LCOV_EXCL_STOP |
| 227 | |
| 228 | /// Does not offer either read or write access to the data, but can be upgraded |
| 229 | /// to a buffer that does. |
| 230 | /// |
| 231 | /// Useful because it implements `Clone`, and does not block other [`DivBufMut`] |
| 232 | /// structures from existing. |
| 233 | #[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:)] |
| 234 | pub struct DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 235 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner.: *mut Innerrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#, |
| 236 | // In the future, consider optimizing by replacing begin with a pointer |
| 237 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#begin.: usize, |
| 238 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#len.: usize, |
| 239 | } |
| 240 | |
| 241 | impl DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 242 | /// Returns the number of bytes the buffer can hold without reallocating. |
| 243 | pub fn capacityrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]capacity().(&self) -> usize { |
| 244 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 245 | inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().() |
| 246 | } |
| 247 | |
| 248 | /// Returns true if the `DivBufShared` has length 0 |
| 249 | pub fn is_emptyrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]is_empty().(&self) -> bool { |
| 250 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 251 | inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() |
| 252 | } |
| 253 | |
| 254 | /// Returns the number of bytes contained in this buffer. |
| 255 | pub fn lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]len().(&self) -> usize { |
| 256 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 257 | inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 258 | } |
| 259 | |
| 260 | #[deprecated(since = "0.3.1", note = "use try_const instead")] |
| 261 | #[doc(hidden)] |
| 262 | pub fn r#tryrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]`r#try`().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#, Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> { |
| 263 | self.try_construst-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]try_const().() |
| 264 | } |
| 265 | |
| 266 | /// Try to create a read-only [`DivBuf`] that refers to the entirety of this |
| 267 | /// buffer. Will fail if there are any [`DivBufMut`] objects referring to |
| 268 | /// this buffer. |
| 269 | /// |
| 270 | /// # Examples |
| 271 | /// ``` |
| 272 | /// # use divbuf::*; |
| 273 | /// let dbs = DivBufShared::with_capacity(4096); |
| 274 | /// let db = dbs.try_const().unwrap(); |
| 275 | /// ``` |
| 276 | /// |
| 277 | /// [`DivBuf`]: struct.DivBuf.html |
| 278 | /// [`DivBufMut`]: struct.DivBufMut.html |
| 279 | pub fn try_construst-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]try_const().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#, Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> { |
| 280 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 281 | if inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shr<Self>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shr<Self>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shr<Self>`]shr().WRITER_SHIFTrust-analyzer cargo divbuf 0.4.1 divbuf/WRITER_SHIFT. 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().0 { |
| 282 | inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_sub().(1, Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 283 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#("Cannot create a DivBuf when DivBufMuts are active")) |
| 284 | } else { |
| 285 | let l = inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 286 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 287 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner., |
| 288 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin.: 0, |
| 289 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.: l, |
| 290 | }) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /// Try to create a mutable `DivBufMut` that refers to the entirety of this |
| 295 | /// buffer. Will fail if there are any [`DivBufMut`] or [`DivBuf`] objects |
| 296 | /// referring to this buffer. |
| 297 | /// |
| 298 | /// # Examples |
| 299 | /// ``` |
| 300 | /// # use divbuf::*; |
| 301 | /// let dbs = DivBufShared::with_capacity(4096); |
| 302 | /// let dbm = dbs.try_mut().unwrap(); |
| 303 | /// ``` |
| 304 | /// |
| 305 | /// [`DivBuf`]: struct.DivBuf.html |
| 306 | /// [`DivBufMut`]: struct.DivBufMut.html |
| 307 | pub fn try_mutrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]try_mut().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#, Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> { |
| 308 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 309 | if inner |
| 310 | .accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors. |
| 311 | .compare_exchangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]compare_exchange().(0, ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER., AcqRelrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#AcqRel#, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) |
| 312 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 313 | { |
| 314 | let l = inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 315 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 316 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner., |
| 317 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin.: 0, |
| 318 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.: l, |
| 319 | }) |
| 320 | } else { |
| 321 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#( |
| 322 | "Cannot create a new DivBufMut when other DivBufs or \ |
| 323 | DivBufMuts are active", |
| 324 | )) |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /// Create a new DivBufShared with an uninitialized buffer of specified |
| 329 | /// length. |
| 330 | /// |
| 331 | /// # Safety |
| 332 | /// |
| 333 | /// This method technically causes undefined behavior, but it works with |
| 334 | /// current compilers. A good replacement is not possible until the |
| 335 | /// read-buf feature stabilizes. |
| 336 | /// |
| 337 | /// <https://github.com/rust-lang/rust/issues/78485> |
| 338 | #[cfg(any(feature = "experimental", docsrs))] |
| 339 | #[cfg_attr(docsrs, doc(cfg(feature = "experimental")))] |
| 340 | #[allow(clippy::uninit_vec)] // Needs the read-buf feature to fix |
| 341 | pub fn uninitializedrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]uninitialized().(capacity: usize) -> Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared] { |
| 342 | let mut v = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<u8>::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity); |
| 343 | // safe because all possible byte patterns for u8 are valid |
| 344 | unsafe { v.set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(capacity) }; |
| 345 | Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]::fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared][`From<Vec<u8>>`]from().(v) |
| 346 | } |
| 347 | |
| 348 | /// Creates a new, empty, `DivBufShared` with a specified capacity. |
| 349 | /// |
| 350 | /// After constructing a `DivBufShared` this way, it can only be populated |
| 351 | /// via a child `DivBufMut`. |
| 352 | pub fn with_capacityrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]with_capacity().(capacity: usize) -> Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared] { |
| 353 | Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared]::fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared][`From<Vec<u8>>`]from().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity)) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 358 | fn fmtrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 359 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 360 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "DivBufShared {{ inner: {:?} }}", inner) |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 365 | fn droprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared][Drop]drop().(&mut self) { |
| 366 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 367 | if inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..fetch_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_sub().(1, Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 |
| 368 | && inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 369 | { |
| 370 | // See the comments in std::sync::Arc::drop for why the fence is |
| 371 | // required. |
| 372 | atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::fencerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/fence().(Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 373 | unsafe { |
| 374 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]from_raw().(self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner.)); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a [u8]> for DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 381 | fn fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared][`From<&'a [u8]>`]from().(src: &'a [u8]) -> DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 382 | DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#::fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared][`From<Vec<u8>>`]from().(src.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()) |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> for DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 387 | fn fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufShared][`From<Vec<u8>>`]from().(src: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 388 | let rc = AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]new().(0); |
| 389 | let sharers = AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]new().(1); |
| 390 | let inner = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(Innerrust-analyzer cargo divbuf 0.4.1 divbuf/Inner# { |
| 391 | vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.: src, |
| 392 | accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors.: rc, |
| 393 | sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers., |
| 394 | }); |
| 395 | DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# { |
| 396 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner.: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::into_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]into_raw().(inner), |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#> for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 402 | type Errorrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[`Vec<u8>`][`TryFrom<DivBufShared>`]Error# = DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#; |
| 403 | |
| 404 | /// Attempt to extract the owned storage from a DivBufShared. |
| 405 | /// |
| 406 | /// This will fail if there are any other living references to this same |
| 407 | /// `DivBufShared` (`DivBuf`s, `DivBufMut`s, etc), in which case the |
| 408 | /// `DivBufShared` will be returned unmodified. |
| 409 | /// |
| 410 | /// # Examples |
| 411 | /// |
| 412 | /// ``` |
| 413 | /// # use divbuf::*; |
| 414 | /// use std::convert::TryInto; |
| 415 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 416 | /// let vec: Vec<u8> = dbs.try_into().unwrap(); |
| 417 | /// assert_eq!(vec, vec![1, 2, 3, 4, 5, 6]); |
| 418 | /// ``` |
| 419 | fn try_fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[`Vec<u8>`][`TryFrom<DivBufShared>`]try_from().(buf: DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[`Vec<u8>`][`TryFrom<DivBufShared>`], Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[`Vec<u8>`][`TryFrom<DivBufShared>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> { |
| 420 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().buf.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner. }; |
| 421 | if inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 |
| 422 | && inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 423 | { |
| 424 | // See the comments in std::sync::Arc::drop for why the fence is |
| 425 | // required. |
| 426 | atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::fencerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/fence().(Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 427 | let mut inner_box = unsafe { Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]from_raw().(buf.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared#inner.) }; |
| 428 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::forgetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/forget().(buf); |
| 429 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut inner_box.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.)) |
| 430 | } else { |
| 431 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(buf) |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | // DivBufShared owns the target of the `inner` pointer, and no method allows |
| 437 | // that pointer to be mutated. Atomic refcounts guarantee that no more than one |
| 438 | // writer at a time can modify `inner`'s contents (as long as DivBufMut is Sync, |
| 439 | // which it is). Therefore, DivBufShared is both Send and Sync. |
| 440 | unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# {} |
| 441 | unsafe impl Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for DivBufSharedrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufShared# {} |
| 442 | |
| 443 | impl DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 444 | /// Create a [`DivBufInaccessible`]. |
| 445 | /// |
| 446 | /// It may later be upgraded to one of the accessible forms. |
| 447 | /// |
| 448 | /// # Examples |
| 449 | /// ``` |
| 450 | /// # use divbuf::*; |
| 451 | /// let dbs = DivBufShared::with_capacity(4096); |
| 452 | /// let db = dbs.try_const().unwrap(); |
| 453 | /// let _dbi = db.clone_inaccessible(); |
| 454 | /// ``` |
| 455 | pub fn clone_inaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]clone_inaccessible().(&self) -> DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 456 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. }; |
| 457 | let old = inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 458 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 459 | DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 460 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner., |
| 461 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin., |
| 462 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len., |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | /// Break the buffer up into equal sized chunks |
| 467 | /// |
| 468 | /// Returns an interator which will yield equal sized chunks as smaller |
| 469 | /// `DivBuf`s. If the `DivBuf` is not evenly divisible by `size`, then the |
| 470 | /// last chunk will be smaller. This method is based on |
| 471 | /// `slice::chunks`, but with a few key differences: |
| 472 | /// |
| 473 | /// - It consumes `self` |
| 474 | /// - Yields smaller `DivBuf`s, not slices |
| 475 | /// - Yields owned objects, not references |
| 476 | /// |
| 477 | /// # Examples |
| 478 | /// ``` |
| 479 | /// # use divbuf::*; |
| 480 | /// let dbs = DivBufShared::from(vec![0, 1, 2, 3, 4, 5, 6, 7]); |
| 481 | /// let db = dbs.try_const().unwrap(); |
| 482 | /// let mut iter = db.into_chunks(3); |
| 483 | /// assert_eq!(&iter.next().unwrap()[..], &[0, 1, 2][..]); |
| 484 | /// assert_eq!(&iter.next().unwrap()[..], &[3, 4, 5][..]); |
| 485 | /// assert_eq!(&iter.next().unwrap()[..], &[6, 7][..]); |
| 486 | /// assert!(&iter.next().is_none()) |
| 487 | /// ``` |
| 488 | pub fn into_chunksrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]into_chunks().(self, size: usize) -> Chunksrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks# { |
| 489 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(size != 0); |
| 490 | Chunksrust-analyzer cargo divbuf 0.4.1 divbuf/Chunks#::newrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[Chunks]new().(self, size) |
| 491 | } |
| 492 | |
| 493 | /// Returns true if the `DivBuf` has length 0 |
| 494 | pub fn is_emptyrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]is_empty().(&self) -> bool { |
| 495 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 496 | } |
| 497 | |
| 498 | /// Get the length of this `DivBuf`, _not_ the underlying storage |
| 499 | pub fn lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]len().(&self) -> usize { |
| 500 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len. |
| 501 | } |
| 502 | |
| 503 | /// Create a new DivBuf that spans a subset of this one. |
| 504 | /// |
| 505 | /// # Examples |
| 506 | /// ``` |
| 507 | /// # use divbuf::*; |
| 508 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 509 | /// let db0 = dbs.try_const().unwrap(); |
| 510 | /// let db1 = db0.slice(1, 4); |
| 511 | /// assert_eq!(db1, [2, 3, 4][..]); |
| 512 | /// ``` |
| 513 | pub fn slicerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]slice().(&self, begin: usize, end: usize) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 514 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(begin <= end); |
| 515 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(end <= self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.); |
| 516 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. }; |
| 517 | let old_accessors = inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 518 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old_accessors &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitAnd<Self>`]bitand(). READER_MASKrust-analyzer cargo divbuf 0.4.1 divbuf/READER_MASK. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 519 | DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 520 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner., |
| 521 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin. 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().begin, |
| 522 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.: end 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().begin, |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /// Creates a new DivBuf that spans a subset of this one, including the end |
| 527 | /// |
| 528 | /// # Examples |
| 529 | /// ``` |
| 530 | /// # use divbuf::*; |
| 531 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 532 | /// let db0 = dbs.try_const().unwrap(); |
| 533 | /// let db1 = db0.slice_from(3); |
| 534 | /// assert_eq!(db1, [4, 5, 6][..]); |
| 535 | /// ``` |
| 536 | pub fn slice_fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]slice_from().(&self, begin: usize) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 537 | self.slicerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]slice().(begin, self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]len().()) |
| 538 | } |
| 539 | |
| 540 | /// Creates a new DivBuf that spans a subset of self, including the |
| 541 | /// beginning |
| 542 | /// |
| 543 | /// # Examples |
| 544 | /// ``` |
| 545 | /// # use divbuf::*; |
| 546 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 547 | /// let db0 = dbs.try_const().unwrap(); |
| 548 | /// let db1 = db0.slice_to(3); |
| 549 | /// assert_eq!(db1, [1, 2, 3][..]); |
| 550 | /// ``` |
| 551 | pub fn slice_torust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]slice_to().(&self, end: usize) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 552 | self.slicerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]slice().(0, end) |
| 553 | } |
| 554 | |
| 555 | /// Splits the DivBuf into two at the given index. |
| 556 | /// |
| 557 | /// Afterwards self contains elements `[0, at)`, and the returned DivBuf |
| 558 | /// contains elements `[at, self.len)`. |
| 559 | /// |
| 560 | /// This is an O(1) operation |
| 561 | /// |
| 562 | /// # Examples |
| 563 | /// |
| 564 | /// ``` |
| 565 | /// # use divbuf::*; |
| 566 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 567 | /// let mut db0 = dbs.try_const().unwrap(); |
| 568 | /// let db1 = db0.split_off(4); |
| 569 | /// assert_eq!(db0, [1, 2, 3, 4][..]); |
| 570 | /// assert_eq!(db1, [5, 6][..]); |
| 571 | /// ``` |
| 572 | pub fn split_offrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]split_off().(&mut self, at: usize) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 573 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(at <= self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len., "Can't split past the end"); |
| 574 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. }; |
| 575 | let old_accessors = inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 576 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old_accessors &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitAnd<Self>`]bitand(). READER_MASKrust-analyzer cargo divbuf 0.4.1 divbuf/READER_MASK. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 577 | let right_half = DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 578 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner., |
| 579 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin. 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().at, |
| 580 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len. 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().at, |
| 581 | }; |
| 582 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len. = at; |
| 583 | right_half |
| 584 | } |
| 585 | |
| 586 | /// Splits the DivBuf into two at the given index. |
| 587 | /// |
| 588 | /// Afterwards self contains elements `[at, self.len)`, and the returned |
| 589 | /// DivBuf contains elements `[0, at)`. |
| 590 | /// This is an O(1) operation. |
| 591 | /// |
| 592 | /// # Examples |
| 593 | /// |
| 594 | /// ``` |
| 595 | /// # use divbuf::*; |
| 596 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 597 | /// let mut db0 = dbs.try_const().unwrap(); |
| 598 | /// let db1 = db0.split_to(4); |
| 599 | /// assert_eq!(db0, [5, 6][..]); |
| 600 | /// assert_eq!(db1, [1, 2, 3, 4][..]); |
| 601 | /// ``` |
| 602 | pub fn split_torust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]split_to().(&mut self, at: usize) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 603 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(at <= self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len., "Can't split past the end"); |
| 604 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. }; |
| 605 | let old_accessors = inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 606 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old_accessors &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitAnd<Self>`]bitand(). READER_MASKrust-analyzer cargo divbuf 0.4.1 divbuf/READER_MASK. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 607 | let left_half = DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 608 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner., |
| 609 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin., |
| 610 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.: at, |
| 611 | }; |
| 612 | self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin. 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().at; |
| 613 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().at; |
| 614 | left_half |
| 615 | } |
| 616 | |
| 617 | /// Attempt to upgrade Self to a writable DivBufMut |
| 618 | /// |
| 619 | /// This will fail if there are any other living DivBufs for this same |
| 620 | /// DivBufShared |
| 621 | /// |
| 622 | /// # Examples |
| 623 | /// ``` |
| 624 | /// # use divbuf::*; |
| 625 | /// let dbs = DivBufShared::with_capacity(4096); |
| 626 | /// let db = dbs.try_const().unwrap(); |
| 627 | /// db.try_mut().unwrap(); |
| 628 | /// ``` |
| 629 | pub fn try_mutrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]try_mut().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#, DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#> { |
| 630 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. }; |
| 631 | if inner |
| 632 | .accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors. |
| 633 | .compare_exchangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]compare_exchange().(1, ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER., AcqRelrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#AcqRel#, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) |
| 634 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 635 | { |
| 636 | let mutable_self = Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 637 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner., |
| 638 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin., |
| 639 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len., |
| 640 | }); |
| 641 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::forgetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/forget().(self); |
| 642 | mutable_self |
| 643 | } else { |
| 644 | // LCOV_EXCL_LINE kcov false negative |
| 645 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(self) |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | /// Combine splitted DivBuf objects back into a contiguous single |
| 650 | /// |
| 651 | /// If `DivBuf` objects were not contiguous originally, the operation will |
| 652 | /// fail and return `other` unmodified |
| 653 | /// |
| 654 | /// # Examples |
| 655 | /// |
| 656 | /// ``` |
| 657 | /// # use divbuf::*; |
| 658 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 659 | /// let mut db0 = dbs.try_const().unwrap(); |
| 660 | /// let db1 = db0.split_off(4); |
| 661 | /// db0.unsplit(db1); |
| 662 | /// assert_eq!(db0, [1, 2, 3, 4, 5, 6][..]); |
| 663 | /// ``` |
| 664 | pub fn unsplitrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]unsplit().(&mut self, other: DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#> { |
| 665 | if self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().other.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. || (self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#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().other.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin. { |
| 666 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(other) |
| 667 | } else { |
| 668 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len. 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().other.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.; |
| 669 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 675 | fn as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`AsRef<[u8]>`]as_ref().(&self) -> &[u8] { |
| 676 | unsafe { |
| 677 | let inner = &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.; |
| 678 | &inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index(). |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<[u8]> for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 684 | fn borrowrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`Borrow<[u8]>`]borrow().(&self) -> &[u8] { |
| 685 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. }; |
| 686 | &inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | impl hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 691 | fn hashrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][Hash]hash().<H>(&self, state: &mut H) |
| 692 | where |
| 693 | H: hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#, |
| 694 | { |
| 695 | let s: &[u8] = self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`AsRef<[u8]>`]as_ref().(); |
| 696 | s.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[`[T]`][Hash]hash().(state); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | impl opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 701 | type Targetrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][Deref]Target# = [u8]; |
| 702 | |
| 703 | fn derefrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][Deref]deref().(&self) -> &[u8] { |
| 704 | unsafe { |
| 705 | let inner = &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.; |
| 706 | &inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index(). |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 712 | fn clonerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][Clone]clone().(&self) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 713 | self.slice_fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf]slice_from().(0) |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 718 | fn droprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][Drop]drop().(&mut self) { |
| 719 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner. }; |
| 720 | if inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_sub().(1, Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 |
| 721 | && inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 722 | { |
| 723 | atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::fencerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/fence().(Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 724 | unsafe { |
| 725 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]from_raw().(self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.)); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# {} |
| 732 | |
| 733 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#> for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 734 | fn fromrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`From<DivBufMut>`]from().(src: DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 735 | src.freezerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]freeze().() |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | impl Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 740 | fn cmprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][Ord]cmp().(&self, other: &DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#) -> cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# { |
| 741 | self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`AsRef<[u8]>`]as_ref().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][Ord]cmp().(other.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`AsRef<[u8]>`]as_ref().()) |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 746 | fn eqrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`PartialEq<Self>`]eq().(&self, other: &DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#) -> bool { |
| 747 | self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`AsRef<[u8]>`]as_ref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().other.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`AsRef<[u8]>`]as_ref().() |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<[u8]> for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 752 | fn eqrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`PartialEq<[u8]>`]eq().(&self, other: &[u8]) -> bool { |
| 753 | self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`AsRef<[u8]>`]as_ref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().other |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 758 | fn partial_cmprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][`PartialOrd<Self>`]partial_cmp().(&self, other: &DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> { |
| 759 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.cmprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBuf][Ord]cmp().(other)) |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // Atomic refcounts provide shared ownership over the `inner` pointer, |
| 764 | // guaranteeing that it won't be freed as long as a `DivBuf` exists. No method |
| 765 | // allows that pointer to be mutated. Atomic refcounts also guarantee that no |
| 766 | // more than one writer at a time can modify `inner`'s contents (as long as |
| 767 | // DivBufMut is Sync, which it is). Therefore, DivBuf is both Send and Sync. |
| 768 | unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# {} |
| 769 | unsafe impl Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# {} |
| 770 | |
| 771 | impl DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 772 | /// Create a [`DivBufInaccessible`]. |
| 773 | /// |
| 774 | /// It may later be upgraded to one of the accessible forms. |
| 775 | /// |
| 776 | /// # Examples |
| 777 | /// ``` |
| 778 | /// # use divbuf::*; |
| 779 | /// let dbs = DivBufShared::with_capacity(4096); |
| 780 | /// let dbm = dbs.try_mut().unwrap(); |
| 781 | /// let _dbi = dbm.clone_inaccessible(); |
| 782 | /// ``` |
| 783 | pub fn clone_inaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]clone_inaccessible().(&self) -> DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 784 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 785 | let old = inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 786 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 787 | DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 788 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner., |
| 789 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin., |
| 790 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len., |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | /// Extend self from iterator, without checking for validity |
| 795 | fn extend_uncheckedrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]extend_unchecked().<'a, T>(&mut self, iter: T) |
| 796 | where |
| 797 | T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a u8>, |
| 798 | { |
| 799 | let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 800 | let oldlen = inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 801 | inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(iter); |
| 802 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. 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().inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..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 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().oldlen; |
| 803 | } |
| 804 | |
| 805 | /// Downgrade this `DivBufMut` into a read-only `DivBuf` |
| 806 | /// |
| 807 | /// Note that this method will always succeed, but subsequently calling |
| 808 | /// [`try_mut`] on the returned `DivBuf` may not. |
| 809 | /// |
| 810 | /// # Examples |
| 811 | /// ``` |
| 812 | /// # use divbuf::*; |
| 813 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 814 | /// let dbm0 = dbs.try_mut().unwrap(); |
| 815 | /// let db : DivBuf = dbm0.freeze(); |
| 816 | /// ``` |
| 817 | /// |
| 818 | /// [`try_mut`]: struct.DivBuf.html#method.try_mut |
| 819 | pub fn freezerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]freeze().(self) -> DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 820 | // Construct a new DivBuf, then drop self. We know that there are no |
| 821 | // other DivButMuts that overlap with this one, so it's safe to create a |
| 822 | // DivBuf whose range is restricted to what self covers |
| 823 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 824 | let old_accessors = inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 825 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old_accessors >> WRITER_SHIFTrust-analyzer cargo divbuf 0.4.1 divbuf/WRITER_SHIFT. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 826 | DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 827 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner., |
| 828 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin., |
| 829 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len., |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | /// Break the buffer up into equal sized chunks |
| 834 | /// |
| 835 | /// Returns an interator which will yield equal sized chunks as smaller |
| 836 | /// `DivBufMut`s. If the `DivBufMut` is not evenly divisible by `size`, |
| 837 | /// then the last chunk will be smaller. This method is based on |
| 838 | /// `slice::chunk_muts`, but with a few key differences: |
| 839 | /// |
| 840 | /// - It consumes `self` |
| 841 | /// - Yields smaller `DivBufMut`s, not slices |
| 842 | /// - Yields owned objects, not references |
| 843 | /// |
| 844 | /// # Examples |
| 845 | /// ``` |
| 846 | /// # use divbuf::*; |
| 847 | /// let dbs = DivBufShared::from(vec![0, 1, 2, 3, 4, 5, 6, 7]); |
| 848 | /// let dbm = dbs.try_mut().unwrap(); |
| 849 | /// let mut iter = dbm.into_chunks(3); |
| 850 | /// assert_eq!(&iter.next().unwrap()[..], &[0, 1, 2][..]); |
| 851 | /// assert_eq!(&iter.next().unwrap()[..], &[3, 4, 5][..]); |
| 852 | /// assert_eq!(&iter.next().unwrap()[..], &[6, 7][..]); |
| 853 | /// assert!(&iter.next().is_none()) |
| 854 | /// ``` |
| 855 | pub fn into_chunksrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]into_chunks().(self, size: usize) -> ChunksMutrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut# { |
| 856 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(size != 0); |
| 857 | ChunksMutrust-analyzer cargo divbuf 0.4.1 divbuf/ChunksMut#::newrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[ChunksMut]new().(self, size) |
| 858 | } |
| 859 | |
| 860 | /// Returns true if the `DivBufMut` has length 0 |
| 861 | pub fn is_emptyrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_empty().(&self) -> bool { |
| 862 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 863 | } |
| 864 | |
| 865 | /// Returns true if the `DivBufMut` extends to the end of the `DivBufShared` |
| 866 | fn is_terminalrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_terminal().(&self) -> bool { |
| 867 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 868 | let oldlen = inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 869 | self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().oldlen |
| 870 | } |
| 871 | |
| 872 | /// Get the length of this `DivBufMut`, _not_ the underlying storage |
| 873 | pub fn lenrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]len().(&self) -> usize { |
| 874 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. |
| 875 | } |
| 876 | |
| 877 | /// Reserves capacity for at least `additional` more bytes to be inserted |
| 878 | /// into the buffer. |
| 879 | /// |
| 880 | /// Like [`extend`], this method will panic if the `DivBufMut` is |
| 881 | /// non-terminal. |
| 882 | /// |
| 883 | /// [`extend`]: #method.extend |
| 884 | pub fn reserverust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]reserve().(&mut self, additional: usize) { |
| 885 | // panic if this DivBufMut does not extend to the end of the |
| 886 | // DivBufShared |
| 887 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 888 | self.is_terminalrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_terminal().(), |
| 889 | "Can't reserve from the middle of a buffer" |
| 890 | ); |
| 891 | let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 892 | inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(additional) |
| 893 | } |
| 894 | |
| 895 | /// Splits the DivBufMut into two at the given index. |
| 896 | /// |
| 897 | /// Afterwards self contains elements `[0, at)`, and the returned DivBufMut |
| 898 | /// contains elements `[at, self.len)`. |
| 899 | /// |
| 900 | /// This is an O(1) operation |
| 901 | /// |
| 902 | /// # Examples |
| 903 | /// |
| 904 | /// ``` |
| 905 | /// # use divbuf::*; |
| 906 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 907 | /// let mut dbm0 = dbs.try_mut().unwrap(); |
| 908 | /// let dbm1 = dbm0.split_off(4); |
| 909 | /// assert_eq!(dbm0, [1, 2, 3, 4][..]); |
| 910 | /// assert_eq!(dbm1, [5, 6][..]); |
| 911 | /// ``` |
| 912 | pub fn split_offrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]split_off().(&mut self, at: usize) -> DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 913 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(at <= self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len., "Can't split past the end"); |
| 914 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 915 | let old_accessors = inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER., Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 916 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old_accessors >> WRITER_SHIFTrust-analyzer cargo divbuf 0.4.1 divbuf/WRITER_SHIFT. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 917 | let right_half = DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 918 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner., |
| 919 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().at, |
| 920 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. 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().at, |
| 921 | }; |
| 922 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. = at; |
| 923 | right_half |
| 924 | } |
| 925 | |
| 926 | /// Splits the DivBufMut into two at the given index. |
| 927 | /// |
| 928 | /// Afterwards self contains elements `[at, self.len)`, and the returned |
| 929 | /// DivBufMut contains elements `[0, at)`. |
| 930 | /// This is an O(1) operation. |
| 931 | /// |
| 932 | /// # Examples |
| 933 | /// |
| 934 | /// ``` |
| 935 | /// # use divbuf::*; |
| 936 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 937 | /// let mut dbm0 = dbs.try_mut().unwrap(); |
| 938 | /// let dbm1 = dbm0.split_to(4); |
| 939 | /// assert_eq!(dbm0, [5, 6][..]); |
| 940 | /// assert_eq!(dbm1, [1, 2, 3, 4][..]); |
| 941 | /// ``` |
| 942 | pub fn split_torust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]split_to().(&mut self, at: usize) -> DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 943 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(at <= self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len., "Can't split past the end"); |
| 944 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 945 | let old_accessors = inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER., Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 946 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old_accessors >> WRITER_SHIFTrust-analyzer cargo divbuf 0.4.1 divbuf/WRITER_SHIFT. >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 947 | let left_half = DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 948 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner., |
| 949 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin., |
| 950 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.: at, |
| 951 | }; |
| 952 | self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().at; |
| 953 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().at; |
| 954 | left_half |
| 955 | } |
| 956 | |
| 957 | /// Attempt to extend this `DivBufMut` with bytes from the provided |
| 958 | /// iterator. |
| 959 | /// |
| 960 | /// If this `DivBufMut` is not terminal, that is if it does not extend to |
| 961 | /// the end of the `DivBufShared`, then this operation will return an error |
| 962 | /// and the buffer will not be modified. The [`extend`] method from the |
| 963 | /// `Extend` Trait, by contrast, will panic under the same condition. |
| 964 | /// |
| 965 | /// # Examples |
| 966 | /// ``` |
| 967 | /// # use divbuf::*; |
| 968 | /// let dbs = DivBufShared::with_capacity(64); |
| 969 | /// let mut dbm0 = dbs.try_mut().unwrap(); |
| 970 | /// assert!(dbm0.try_extend([1, 2, 3].iter()).is_ok()); |
| 971 | /// ``` |
| 972 | /// |
| 973 | /// [`extend`]: #method.extend |
| 974 | pub fn try_extendrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]try_extend().<'a, T>(&mut self, iter: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> |
| 975 | where |
| 976 | T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a u8>, |
| 977 | { |
| 978 | if self.is_terminalrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_terminal().() { |
| 979 | self.extend_uncheckedrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]extend_unchecked().(iter); |
| 980 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 981 | } else { |
| 982 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#("Can't extend into the middle of a buffer")) |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | /// Attempt to resize this `DivBufMut` in-place. |
| 987 | /// |
| 988 | /// If `new_len` is greater than the existing length, then the buffer will |
| 989 | /// be extended by the difference, with each element filled by `value`. If |
| 990 | /// `new_len` is less than the existing length, then the buffer is simply |
| 991 | /// truncated. |
| 992 | /// |
| 993 | /// If this `DivBufMut` is not terminal, that is if it does not extend to |
| 994 | /// the end of the `DivBufShared`, then this operation will return an error |
| 995 | /// and the buffer will not be modified. |
| 996 | /// |
| 997 | /// # Examples |
| 998 | /// ``` |
| 999 | /// # use divbuf::*; |
| 1000 | /// let dbs = DivBufShared::with_capacity(64); |
| 1001 | /// let mut dbm0 = dbs.try_mut().unwrap(); |
| 1002 | /// assert!(dbm0.try_resize(4, 0).is_ok()); |
| 1003 | /// assert_eq!(&dbm0[..], &[0, 0, 0, 0][..]); |
| 1004 | /// ``` |
| 1005 | pub fn try_resizerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]try_resize().( |
| 1006 | &mut self, |
| 1007 | new_len: usize, |
| 1008 | value: u8, |
| 1009 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> { |
| 1010 | if self.is_terminalrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_terminal().() { |
| 1011 | let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 1012 | inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..resizerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]resize().(new_len 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().self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin., value); |
| 1013 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. = new_len; |
| 1014 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1015 | } else { |
| 1016 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#("Can't resize from a non-terminal buffer")) |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | /// Shortens the buffer, keeping the first `len` bytes and dropping the |
| 1021 | /// rest. |
| 1022 | /// |
| 1023 | /// If `len` is greater than the buffer's current length, this has no |
| 1024 | /// effect. |
| 1025 | /// |
| 1026 | /// Like [`try_extend`], will fail if this DivButMut is non-terminal. |
| 1027 | /// |
| 1028 | /// # Examples |
| 1029 | /// |
| 1030 | /// ``` |
| 1031 | /// # use divbuf::*; |
| 1032 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 1033 | /// let mut dbm0 = dbs.try_mut().unwrap(); |
| 1034 | /// assert!(dbm0.try_truncate(3).is_ok()); |
| 1035 | /// assert_eq!(dbm0, [1, 2, 3][..]); |
| 1036 | /// ``` |
| 1037 | /// |
| 1038 | /// [`try_extend`]: #method.try_extend |
| 1039 | pub fn try_truncaterust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]try_truncate().(&mut self, len: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> { |
| 1040 | if self.is_terminalrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_terminal().() { |
| 1041 | let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 1042 | inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().len); |
| 1043 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len., len); |
| 1044 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1045 | } else { |
| 1046 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#("Can't truncate a non-terminal DivBufMut")) |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | /// Combine splitted DivBufMut objects back into a contiguous single |
| 1051 | /// |
| 1052 | /// If `DivBufMut` objects were not contiguous originally, the operation |
| 1053 | /// will fail and return `other` unmodified |
| 1054 | /// |
| 1055 | /// # Examples |
| 1056 | /// |
| 1057 | /// ``` |
| 1058 | /// # use divbuf::*; |
| 1059 | /// let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]); |
| 1060 | /// let mut dbm0 = dbs.try_mut().unwrap(); |
| 1061 | /// let dbm1 = dbm0.split_off(4); |
| 1062 | /// dbm0.unsplit(dbm1); |
| 1063 | /// assert_eq!(dbm0, [1, 2, 3, 4, 5, 6][..]); |
| 1064 | /// ``` |
| 1065 | pub fn unsplitrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]unsplit().(&mut self, other: DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#> { |
| 1066 | if self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().other.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. || (self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#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().other.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. { |
| 1067 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(other) |
| 1068 | } else { |
| 1069 | self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len. 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().other.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.; |
| 1070 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1076 | fn as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`AsRef<[u8]>`]as_ref().(&self) -> &[u8] { |
| 1077 | unsafe { |
| 1078 | let inner = &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.; |
| 1079 | &inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index(). |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<[u8]> for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1085 | fn borrowrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`Borrow<[u8]>`]borrow().(&self) -> &[u8] { |
| 1086 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 1087 | &inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | impl BorrowMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/BorrowMut#<[u8]> for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1092 | fn borrow_mutrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`BorrowMut<[u8]>`]borrow_mut().(&mut self) -> &mut [u8] { |
| 1093 | let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 1094 | &mut inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | impl opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1099 | type Targetrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Deref]Target# = [u8]; |
| 1100 | |
| 1101 | fn derefrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Deref]deref().(&self) -> &[u8] { |
| 1102 | unsafe { |
| 1103 | let inner = &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.; |
| 1104 | &inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`Index<I>`]index(). |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | impl opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1110 | fn deref_mutrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][DerefMut]deref_mut().(&mut self) -> &mut [u8] { |
| 1111 | unsafe { |
| 1112 | let inner = &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.; |
| 1113 | &mut inner.vecrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#vec.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin. 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().self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`IndexMut<I>`]index_mut(). |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1119 | fn droprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Drop]drop().(&mut self) { |
| 1120 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner. }; |
| 1121 | if inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_sub().(ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER., Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER. |
| 1122 | && inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 1123 | { |
| 1124 | atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::fencerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/fence().(Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 1125 | unsafe { |
| 1126 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]from_raw().(self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.)); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | impl<'a> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<&'a u8> for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1133 | fn extendrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`Extend<&'a u8>`]extend().<T>(&mut self, iter: T) |
| 1134 | where |
| 1135 | T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a u8>, |
| 1136 | { |
| 1137 | // panic if this DivBufMut does not extend to the end of the |
| 1138 | // DivBufShared |
| 1139 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 1140 | self.is_terminalrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]is_terminal().(), |
| 1141 | "Can't extend into the middle of a buffer" |
| 1142 | ); |
| 1143 | self.extend_uncheckedrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]extend_unchecked().(iter); |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | impl hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1148 | fn hashrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Hash]hash().<H>(&self, state: &mut H) |
| 1149 | where |
| 1150 | H: hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#, |
| 1151 | { |
| 1152 | let s: &[u8] = self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`AsRef<[u8]>`]as_ref().(); |
| 1153 | s.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[`[T]`][Hash]hash().(state); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# {} |
| 1158 | |
| 1159 | impl Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1160 | fn cmprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Ord]cmp().(&self, other: &DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#) -> cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# { |
| 1161 | self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`AsRef<[u8]>`]as_ref().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/cmp/impl#[`[T]`][Ord]cmp().(other.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`AsRef<[u8]>`]as_ref().()) |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1166 | fn eqrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`PartialEq<Self>`]eq().(&self, other: &DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#) -> bool { |
| 1167 | self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`AsRef<[u8]>`]as_ref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().other.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`AsRef<[u8]>`]as_ref().() |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<[u8]> for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1172 | fn eqrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`PartialEq<[u8]>`]eq().(&self, other: &[u8]) -> bool { |
| 1173 | self.as_refrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`AsRef<[u8]>`]as_ref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().other |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1178 | fn partial_cmprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][`PartialOrd<Self>`]partial_cmp().(&self, other: &DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> { |
| 1179 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.cmprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Ord]cmp().(other)) |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | // Atomic refcounts provide shared ownership over the `inner` pointer, |
| 1184 | // guaranteeing that it won't be freed as long as a `DivBufMut` exists. No method |
| 1185 | // allows that pointer to be mutated. Atomic refcounts also guarantee that no |
| 1186 | // more than one writer at a time can modify `inner`'s contents (as long as |
| 1187 | // DivBufMut is Sync, which it is). Thereforce, DivBufMut is Send. And while |
| 1188 | // DivBufMut allows `inner`'s contents to be mutated, it does not provide |
| 1189 | // interior mutability; a &mut DivButMut is required. Therefore, DivBufMut is |
| 1190 | // Sync as well. |
| 1191 | unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# {} |
| 1192 | unsafe impl Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# {} |
| 1193 | |
| 1194 | impl 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# for DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1195 | fn writerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Write]write().(&mut self, buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 1196 | self.try_extendrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]try_extend().(buf) |
| 1197 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|_| buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 1198 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|s| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, s)) |
| 1199 | } |
| 1200 | |
| 1201 | fn write_allrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Write]write_all().(&mut self, buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 1202 | self.try_extendrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut]try_extend().(buf) |
| 1203 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|s| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, s)) |
| 1204 | } |
| 1205 | |
| 1206 | fn flushrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufMut][Write]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 1207 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | impl DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 1212 | /// Try to upgrade to a [`DivBuf`]. |
| 1213 | /// |
| 1214 | /// Will fail if there are any [`DivBufMut`]s referring to this same buffer. |
| 1215 | /// |
| 1216 | /// # Examples |
| 1217 | /// ``` |
| 1218 | /// # use divbuf::*; |
| 1219 | /// let dbs = DivBufShared::with_capacity(4096); |
| 1220 | /// let dbm = dbs.try_mut().unwrap(); |
| 1221 | /// let dbi = dbm.clone_inaccessible(); |
| 1222 | /// drop(dbm); |
| 1223 | /// let _db: DivBuf = dbi.try_const().unwrap(); |
| 1224 | /// ``` |
| 1225 | pub fn try_construst-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufInaccessible]try_const().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#, Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> { |
| 1226 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner. }; |
| 1227 | if inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shr<Self>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shr<Self>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shr<Self>`]shr().WRITER_SHIFTrust-analyzer cargo divbuf 0.4.1 divbuf/WRITER_SHIFT. 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().0 { |
| 1228 | inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..fetch_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_sub().(1, Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#); |
| 1229 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#("Cannot create a DivBuf when DivBufMuts are active")) |
| 1230 | } else { |
| 1231 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DivBufrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf# { |
| 1232 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner., |
| 1233 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#begin., |
| 1234 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBuf#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#len., |
| 1235 | }) |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | /// Try to upgrade to a [`DivBufMut`]. |
| 1240 | /// |
| 1241 | /// Will fail if there are any [`DivBufMut`]s referring to this same buffer. |
| 1242 | /// |
| 1243 | /// # Examples |
| 1244 | /// ``` |
| 1245 | /// # use divbuf::*; |
| 1246 | /// let dbs = DivBufShared::with_capacity(4096); |
| 1247 | /// let dbm = dbs.try_mut().unwrap(); |
| 1248 | /// let dbi = dbm.clone_inaccessible(); |
| 1249 | /// drop(dbm); |
| 1250 | /// let _dbm: DivBufMut = dbi.try_mut().unwrap(); |
| 1251 | /// ``` |
| 1252 | pub fn try_mutrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufInaccessible]try_mut().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#, Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#> { |
| 1253 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner. }; |
| 1254 | if inner |
| 1255 | .accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors. |
| 1256 | .compare_exchangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]compare_exchange().(0, ONE_WRITERrust-analyzer cargo divbuf 0.4.1 divbuf/ONE_WRITER., AcqRelrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#AcqRel#, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) |
| 1257 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 1258 | { |
| 1259 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DivBufMutrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut# { |
| 1260 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner., |
| 1261 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#begin., |
| 1262 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufMut#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#len., |
| 1263 | }) |
| 1264 | } else { |
| 1265 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo divbuf 0.4.1 divbuf/Error#("Cannot upgrade when DivBufMuts are active")) |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 1271 | fn clonerust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufInaccessible][Clone]clone().(&self) -> Selfrust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufInaccessible][Clone] { |
| 1272 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner. }; |
| 1273 | let old = inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_add().(1, Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 1274 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(old >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 1275 | DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 1276 | innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner.: self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner., |
| 1277 | beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#begin.: self.beginrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#begin., |
| 1278 | lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#len.: self.lenrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#len., |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# { |
| 1284 | fn droprust-analyzer cargo divbuf 0.4.1 divbuf/impl#[DivBufInaccessible][Drop]drop().(&mut self) { |
| 1285 | let inner = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner. }; |
| 1286 | if inner.sharersrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#sharers..fetch_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]fetch_sub().(1, Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 |
| 1287 | && inner.accessorsrust-analyzer cargo divbuf 0.4.1 divbuf/Inner#accessors..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Relaxedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Relaxed#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 1288 | { |
| 1289 | // See the comments in std::sync::Arc::drop for why the fence is |
| 1290 | // required. |
| 1291 | atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::fencerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/fence().(Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#); |
| 1292 | unsafe { |
| 1293 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]from_raw().(self.innerrust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible#inner.)); |
| 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | // DivBufInaccessible owns the target of the `inner` pointer, and no method |
| 1300 | // allows that pointer to be mutated. Atomic refcounts guarantee that no more |
| 1301 | // than one writer at a time can modify `inner`'s contents (as long as DivBufMut |
| 1302 | // is Sync, which it is). Therefore, DivBufInaccessible is both Send and Sync. |
| 1303 | unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# {} |
| 1304 | unsafe impl Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for DivBufInaccessiblerust-analyzer cargo divbuf 0.4.1 divbuf/DivBufInaccessible# {} |