| 1 | use craterust-analyzer cargo ringbuf 0.3.3 crate/::{ |
| 2 | ring_bufferrust-analyzer cargo ringbuf 0.3.3 ring_buffer/::{RbBaserust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbBase#, RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#, RbReadCacherust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/RbReadCache#, RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#, RbWraprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#}, |
| 3 | utilsrust-analyzer cargo ringbuf 0.3.3 utils/::{slice_assume_init_mutrust-analyzer cargo ringbuf 0.3.3 utils/slice_assume_init_mut()., slice_assume_init_refrust-analyzer cargo ringbuf 0.3.3 utils/slice_assume_init_ref()., write_uninit_slicerust-analyzer cargo ringbuf 0.3.3 utils/write_uninit_slice().}, |
| 4 | }; |
| 5 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/, iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#, markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#}; |
| 6 | |
| 7 | #[cfg(feature = "std")] |
| 8 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 9 | |
| 10 | /// Consumer part of ring buffer. |
| 11 | /// |
| 12 | /// # Mode |
| 13 | /// |
| 14 | /// It can operate in immediate (by default) or postponed mode. |
| 15 | /// Mode could be switched using [`Self::postponed`]/[`Self::into_postponed`] and [`Self::into_immediate`] methods. |
| 16 | /// |
| 17 | /// + In immediate mode removed and inserted items are automatically synchronized with the other end. |
| 18 | /// + In postponed mode synchronization occurs only when [`Self::sync`] or [`Self::into_immediate`] is called or when `Self` is dropped. |
| 19 | /// The reason to use postponed mode is that multiple subsequent operations are performed faster due to less frequent cache synchronization. |
| 20 | pub struct Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#> |
| 21 | where |
| 22 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 23 | { |
| 24 | targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target.: R, |
| 25 | _phantomrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#_phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T>, |
| 26 | } |
| 27 | |
| 28 | impl<T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#> Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, R> |
| 29 | where |
| 30 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 31 | { |
| 32 | /// Creates consumer from the ring buffer reference. |
| 33 | /// |
| 34 | /// # Safety |
| 35 | /// |
| 36 | /// There must be only one consumer containing the same ring buffer reference. |
| 37 | pub unsafe fn newrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]new().(target: R) -> Selfrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`] { |
| 38 | Selfrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`] { |
| 39 | targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target., |
| 40 | _phantomrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#_phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /// Returns reference to the underlying ring buffer. |
| 45 | #[inline] |
| 46 | pub fn rbrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]rb().(&self) -> &R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb# { |
| 47 | &self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target. |
| 48 | } |
| 49 | |
| 50 | /// Consumes `self` and returns underlying ring buffer reference. |
| 51 | pub fn into_rb_refrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]into_rb_ref().(self) -> R { |
| 52 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target. |
| 53 | } |
| 54 | |
| 55 | /// Returns postponed consumer that borrows [`Self`]. |
| 56 | pub fn postponedrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]postponed().(&mut self) -> Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, RbWraprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#<RbReadCacherust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/RbReadCache#<T, &R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#>>> { |
| 57 | unsafe { Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#::newrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]new().(RbWraprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#(RbReadCacherust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/RbReadCache#::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/impl#[`RbReadCache<T, R>`]new().(&self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target.))) } |
| 58 | } |
| 59 | |
| 60 | /// Transforms [`Self`] into postponed consumer. |
| 61 | pub fn into_postponedrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]into_postponed().(self) -> Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, RbWraprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#<RbReadCacherust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/RbReadCache#<T, R>>> { |
| 62 | unsafe { Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#::newrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]new().(RbWraprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#(RbReadCacherust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/RbReadCache#::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/impl#[`RbReadCache<T, R>`]new().(self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target.))) } |
| 63 | } |
| 64 | |
| 65 | /// Returns capacity of the ring buffer. |
| 66 | /// |
| 67 | /// The capacity of the buffer is constant. |
| 68 | #[inline] |
| 69 | pub fn capacityrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]capacity().(&self) -> usize { |
| 70 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..capacity_nonzerorust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbBase#capacity_nonzero().().getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() |
| 71 | } |
| 72 | |
| 73 | /// Checks if the ring buffer is empty. |
| 74 | /// |
| 75 | /// *The result may become irrelevant at any time because of concurring producer activity.* |
| 76 | #[inline] |
| 77 | pub fn is_emptyrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]is_empty().(&self) -> bool { |
| 78 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..is_emptyrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbBase#is_empty().() |
| 79 | } |
| 80 | |
| 81 | /// Checks if the ring buffer is full. |
| 82 | #[inline] |
| 83 | pub fn is_fullrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]is_full().(&self) -> bool { |
| 84 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..is_fullrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbBase#is_full().() |
| 85 | } |
| 86 | |
| 87 | /// The number of items stored in the buffer. |
| 88 | /// |
| 89 | /// *Actual number may be greater than the returned value because of concurring producer activity.* |
| 90 | #[inline] |
| 91 | pub fn lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]len().(&self) -> usize { |
| 92 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..occupied_lenrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbBase#occupied_len().() |
| 93 | } |
| 94 | |
| 95 | /// The number of remaining free places in the buffer. |
| 96 | /// |
| 97 | /// *Actual number may be less than the returned value because of concurring producer activity.* |
| 98 | #[inline] |
| 99 | pub fn free_lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]free_len().(&self) -> usize { |
| 100 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..vacant_lenrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbBase#vacant_len().() |
| 101 | } |
| 102 | |
| 103 | /// Provides a direct access to the ring buffer occupied memory. |
| 104 | /// The difference from [`Self::as_slices`] is that this method provides slices of [`MaybeUninit<T>`], so items may be moved out of slices. |
| 105 | /// |
| 106 | /// Returns a pair of slices of stored items, the second one may be empty. |
| 107 | /// Elements with lower indices in slice are older. First slice contains older items that second one. |
| 108 | /// |
| 109 | /// # Safety |
| 110 | /// |
| 111 | /// All items are initialized. Elements must be removed starting from the beginning of first slice. |
| 112 | /// When all items are removed from the first slice then items must be removed from the beginning of the second slice. |
| 113 | /// |
| 114 | /// *This method must be followed by [`Self::advance`] call with the number of items being removed previously as argument.* |
| 115 | /// *No other mutating calls allowed before that.* |
| 116 | #[inline] |
| 117 | pub unsafe fn as_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_uninit_slices().(&self) -> (&[MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#<T>], &[MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#<T>]) { |
| 118 | let (left, right) = self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..occupied_slicesrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#occupied_slices().(); |
| 119 | (left as &[_], right as &[_]) |
| 120 | } |
| 121 | |
| 122 | /// Provides a direct mutable access to the ring buffer occupied memory. |
| 123 | /// |
| 124 | /// Same as [`Self::as_uninit_slices`]. |
| 125 | /// |
| 126 | /// # Safety |
| 127 | /// |
| 128 | /// See [`Self::as_uninit_slices`]. |
| 129 | #[inline] |
| 130 | pub unsafe fn as_mut_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_mut_uninit_slices().(&self) -> (&mut [MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#<T>], &mut [MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#<T>]) { |
| 131 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..occupied_slicesrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#occupied_slices().() |
| 132 | } |
| 133 | |
| 134 | /// Moves `head` target by `count` places. |
| 135 | /// |
| 136 | /// # Safety |
| 137 | /// |
| 138 | /// First `count` items in occupied memory must be moved out or dropped. |
| 139 | #[inline] |
| 140 | pub unsafe fn advancerust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]advance().(&mut self, count: usize) { |
| 141 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..advance_headrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#advance_head().(count); |
| 142 | } |
| 143 | |
| 144 | /// Returns a pair of slices which contain, in order, the contents of the ring buffer. |
| 145 | #[inline] |
| 146 | pub fn as_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_slices().(&self) -> (&[T], &[T]) { |
| 147 | unsafe { |
| 148 | let (left, right) = self.as_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_uninit_slices().(); |
| 149 | (slice_assume_init_refrust-analyzer cargo ringbuf 0.3.3 utils/slice_assume_init_ref().(left), slice_assume_init_refrust-analyzer cargo ringbuf 0.3.3 utils/slice_assume_init_ref().(right)) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /// Returns a pair of mutable slices which contain, in order, the contents of the ring buffer. |
| 154 | #[inline] |
| 155 | pub fn as_mut_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_mut_slices().(&mut self) -> (&mut [T], &mut [T]) { |
| 156 | unsafe { |
| 157 | let (left, right) = self.as_mut_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_mut_uninit_slices().(); |
| 158 | (slice_assume_init_mutrust-analyzer cargo ringbuf 0.3.3 utils/slice_assume_init_mut().(left), slice_assume_init_mutrust-analyzer cargo ringbuf 0.3.3 utils/slice_assume_init_mut().(right)) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /// Removes latest item from the ring buffer and returns it. |
| 163 | /// |
| 164 | /// Returns `None` if the ring buffer is empty. |
| 165 | pub fn poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 166 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_emptyrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]is_empty().() { |
| 167 | let elem = unsafe { |
| 168 | self.as_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_uninit_slices().() |
| 169 | .0 |
| 170 | .get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(0) |
| 171 | .assume_init_readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init_read().() |
| 172 | }; |
| 173 | unsafe { self.advancerust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]advance().(1) }; |
| 174 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elem) |
| 175 | } else { |
| 176 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /// Returns an iterator that removes items one by one from the ring buffer. |
| 181 | /// |
| 182 | /// Iterator provides only items that are available for consumer at the moment of `pop_iter` call, it will not contain new items added after it was created. |
| 183 | /// |
| 184 | /// *Information about removed items is commited to the buffer only when iterator is destroyed.* |
| 185 | pub fn pop_iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_iter().(&mut self) -> PopIteratorrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#<'_, T, R> { |
| 186 | PopIteratorrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#::newrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`]new().(&self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target.) |
| 187 | } |
| 188 | |
| 189 | /// Returns a front-to-back iterator containing references to items in the ring buffer. |
| 190 | /// |
| 191 | /// This iterator does not remove items out of the ring buffer. |
| 192 | pub fn iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]iter().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &T> + '_ { |
| 193 | let (left, right) = self.as_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_slices().(); |
| 194 | left.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(right.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) |
| 195 | } |
| 196 | |
| 197 | /// Returns a front-to-back iterator that returns mutable references to items in the ring buffer. |
| 198 | /// |
| 199 | /// This iterator does not remove items out of the ring buffer. |
| 200 | pub fn iter_mutrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]iter_mut().(&mut self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &mut T> + '_ { |
| 201 | let (left, right) = self.as_mut_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_mut_slices().(); |
| 202 | left.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(right.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().()) |
| 203 | } |
| 204 | |
| 205 | /// Removes at most `n` and at least `min(n, Self::len())` items from the buffer and safely drops them. |
| 206 | /// |
| 207 | /// If there is no concurring producer activity then exactly `min(n, Self::len())` items are removed. |
| 208 | /// |
| 209 | /// Returns the number of deleted items. |
| 210 | /// |
| 211 | #[cfg_attr( |
| 212 | feature = "alloc", |
| 213 | doc = r##" |
| 214 | ```rust |
| 215 | # extern crate ringbuf; |
| 216 | # use ringbuf::HeapRb; |
| 217 | # fn main() { |
| 218 | let target = HeapRb::<i32>::new(8); |
| 219 | let (mut prod, mut cons) = target.split(); |
| 220 | |
| 221 | assert_eq!(prod.push_iter(&mut (0..8)), 8); |
| 222 | |
| 223 | assert_eq!(cons.skip(4), 4); |
| 224 | assert_eq!(cons.skip(8), 4); |
| 225 | assert_eq!(cons.skip(8), 0); |
| 226 | # } |
| 227 | ``` |
| 228 | "## |
| 229 | )] |
| 230 | pub fn skiprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]skip().(&mut self, count: usize) -> usize { |
| 231 | let count = 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().(count, self.lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]len().()); |
| 232 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unsafe { self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..skip_internalrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#skip_internal().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(count)) }, count); |
| 233 | count |
| 234 | } |
| 235 | |
| 236 | /// Removes all items from the buffer and safely drops them. |
| 237 | /// |
| 238 | /// Returns the number of deleted items. |
| 239 | pub fn clearrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]clear().(&mut self) -> usize { |
| 240 | unsafe { self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..skip_internalrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#skip_internal().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /// An iterator that removes items from the ring buffer. |
| 245 | pub struct PopIteratorrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#<'a, T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> |
| 246 | where |
| 247 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 248 | { |
| 249 | targetrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#target.: &'a R, |
| 250 | slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices.: (&'a [MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#<T>], &'a [MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#<T>]), |
| 251 | initial_lenrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#initial_len.: usize, |
| 252 | } |
| 253 | |
| 254 | impl<'a, T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> PopIteratorrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#<'a, T, R> |
| 255 | where |
| 256 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 257 | { |
| 258 | pub(craterust-analyzer cargo ringbuf 0.3.3 crate/) fn newrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`]new().(target: &'a R) -> Selfrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`] { |
| 259 | let slices = unsafe { target.occupied_slicesrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#occupied_slices().() }; |
| 260 | Selfrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`] { |
| 261 | targetrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#target., |
| 262 | initial_lenrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#initial_len.: slices.0.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/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().slices.1.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 263 | slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices.: (slices.0, slices.1), |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | impl<'a, T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for PopIteratorrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#<'a, T, R> |
| 269 | where |
| 270 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 271 | { |
| 272 | type Itemrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`][Iterator]Item# = T; |
| 273 | #[inline] |
| 274 | fn nextrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 275 | match self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..0.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 276 | 0 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 277 | n => { |
| 278 | let item = unsafe { self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..0.get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(0).assume_init_readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init_read().() }; |
| 279 | if n 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 { |
| 280 | (self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..0, self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..1) = (self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..1, &[]); |
| 281 | } else { |
| 282 | self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..0 = unsafe { self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..0.get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n) }; |
| 283 | } |
| 284 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | #[inline] |
| 289 | fn size_hintrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 290 | (self.lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`][ExactSizeIterator]len().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`][ExactSizeIterator]len().())) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | impl<'a, T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for PopIteratorrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#<'a, T, R> |
| 295 | where |
| 296 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 297 | { |
| 298 | fn lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`][ExactSizeIterator]len().(&self) -> usize { |
| 299 | self.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..0.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/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.slicesrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#slices..1.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | impl<'a, T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for PopIteratorrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#<'a, T, R> |
| 304 | where |
| 305 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 306 | { |
| 307 | fn droprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`PopIterator<'a, T, R>`][Drop]drop().(&mut self) { |
| 308 | unsafe { self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#target..advance_headrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#advance_head().(self.initial_lenrust-analyzer cargo ringbuf 0.3.3 consumer/PopIterator#initial_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().self.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/impl#[`&mut I`][ExactSizeIterator]len().()) }; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | impl<T: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#> Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, R> |
| 313 | where |
| 314 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 315 | { |
| 316 | /// Removes first items from the ring buffer and writes them into a slice. |
| 317 | /// Elements must be [`Copy`]. |
| 318 | /// |
| 319 | /// Returns count of items been removed from the ring buffer. |
| 320 | pub fn pop_slicerust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_slice().(&mut self, elems: &mut [T]) -> usize { |
| 321 | let (left, right) = unsafe { self.as_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_uninit_slices().() }; |
| 322 | let count = if elems.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().left.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 323 | unsafe { write_uninit_slicerust-analyzer cargo ringbuf 0.3.3 utils/write_uninit_slice().(elems, &left[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#elems.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) }; |
| 324 | elems.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 325 | } else { |
| 326 | let (left_elems, elems) = elems.split_at_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at_mut().(left.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 327 | unsafe { write_uninit_slicerust-analyzer cargo ringbuf 0.3.3 utils/write_uninit_slice().(left_elems, left) }; |
| 328 | left.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 329 | +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().if elems.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().right.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 330 | unsafe { write_uninit_slicerust-analyzer cargo ringbuf 0.3.3 utils/write_uninit_slice().(elems, &right[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#elems.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) }; |
| 331 | elems.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 332 | } else { |
| 333 | unsafe { write_uninit_slicerust-analyzer cargo ringbuf 0.3.3 utils/write_uninit_slice().(&mut elems[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#right.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()., right) }; |
| 334 | right.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() |
| 335 | } |
| 336 | }; |
| 337 | unsafe { self.advancerust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]advance().(count) }; |
| 338 | count |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /// Postponed consumer. |
| 343 | pub type PostponedConsumerrust-analyzer cargo ringbuf 0.3.3 consumer/PostponedConsumer#<T, R> = Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, RbWraprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#<RbReadCacherust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/RbReadCache#<T, R>>>; |
| 344 | |
| 345 | impl<T, R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#> PostponedConsumerrust-analyzer cargo ringbuf 0.3.3 consumer/PostponedConsumer#<T, R> |
| 346 | where |
| 347 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 348 | { |
| 349 | /// Create new postponed consumer. |
| 350 | /// |
| 351 | /// # Safety |
| 352 | /// |
| 353 | /// There must be only one consumer containing the same ring buffer reference. |
| 354 | pub unsafe fn new_postponedrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, RbWrap<RbReadCache<T, R>>>`]new_postponed().(target: R) -> Selfrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, RbWrap<RbReadCache<T, R>>>`] { |
| 355 | Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#::newrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]new().(RbWraprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#(RbReadCacherust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/RbReadCache#::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/impl#[`RbReadCache<T, R>`]new().(target))) |
| 356 | } |
| 357 | |
| 358 | /// Synchronize changes with the ring buffer. |
| 359 | /// |
| 360 | /// Postponed consumer requires manual synchronization to make freed space visible for the producer. |
| 361 | pub fn syncrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, RbWrap<RbReadCache<T, R>>>`]sync().(&mut self) { |
| 362 | self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..0rust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#0..syncrust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/impl#[`RbReadCache<T, R>`]sync().(); |
| 363 | } |
| 364 | |
| 365 | /// Synchronize and transform back to immediate consumer. |
| 366 | pub fn into_immediaterust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, RbWrap<RbReadCache<T, R>>>`]into_immediate().(self) -> Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, R> { |
| 367 | unsafe { Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#::newrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]new().(self.targetrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#target..0rust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbWrap#0..releaserust-analyzer cargo ringbuf 0.3.3 ring_buffer/cache/impl#[`RbReadCache<T, R>`]release().()) } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | #[cfg(feature = "std")] |
| 372 | impl<R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#> Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<u8, R> |
| 373 | where |
| 374 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<u8>, |
| 375 | { |
| 376 | /// Removes at most first `count` bytes from the ring buffer and writes them into a [`Write`] instance. |
| 377 | /// If `count` is `None` then as much as possible bytes will be written. |
| 378 | /// |
| 379 | /// Returns `Ok(n)` if `write` succeeded. `n` is number of bytes been written. |
| 380 | /// `n == 0` means that either `write` returned zero or ring buffer is empty. |
| 381 | /// |
| 382 | /// If `write` is failed then original error is returned. In this case it is guaranteed that no items was written to the writer. |
| 383 | /// To achieve this we write only one contiguous slice at once. So this call may write less than `len` items even if the writer is ready to get more. |
| 384 | pub fn write_intorust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<u8, R>`]write_into().<P: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>( |
| 385 | &mut self, |
| 386 | writer: &mut P, |
| 387 | count: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 388 | ) -> 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> { |
| 389 | let (left, _) = unsafe { self.as_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_uninit_slices().() }; |
| 390 | let count = 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().(count.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(left.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()), left.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 391 | let left_init = unsafe { slice_assume_init_refrust-analyzer cargo ringbuf 0.3.3 utils/slice_assume_init_ref().(&left[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#count]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) }; |
| 392 | |
| 393 | let write_count = writer.writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(left_init)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 394 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(write_count <= count); |
| 395 | unsafe { self.advancerust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]advance().(write_count) }; |
| 396 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(write_count) |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | #[cfg(feature = "std")] |
| 401 | impl<R: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#> Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<u8, R> |
| 402 | where |
| 403 | R::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<u8>, |
| 404 | { |
| 405 | fn readrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<u8, R>`][Read]read().(&mut self, buffer: &mut [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> { |
| 406 | let n = self.pop_slicerust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_slice().(buffer); |
| 407 | if n 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 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().buffer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 408 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(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#::WouldBlockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#WouldBlock#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 409 | } else { |
| 410 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(n) |
| 411 | } |
| 412 | } |
| 413 | } |