| 1 | use craterust-analyzer cargo ringbuf 0.3.3 crate/::{ |
| 2 | consumerrust-analyzer cargo ringbuf 0.3.3 consumer/::Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#, |
| 3 | producerrust-analyzer cargo ringbuf 0.3.3 producer/::Producerrust-analyzer cargo ringbuf 0.3.3 producer/Producer#, |
| 4 | ring_bufferrust-analyzer cargo ringbuf 0.3.3 ring_buffer/::{RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#, RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#, RbWriterust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbWrite#}, |
| 5 | }; |
| 6 | |
| 7 | /// Moves at most `count` items from the `src` consumer to the `dst` producer. |
| 8 | /// |
| 9 | /// Consumer and producer may be of different buffers as well as of the same one. |
| 10 | /// `count` is the number of items being moved, if `None` - as much as possible items will be moved. |
| 11 | /// |
| 12 | /// Returns number of items been moved. |
| 13 | pub fn transferrust-analyzer cargo ringbuf 0.3.3 transfer/transfer().<T, Rs: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#, Rd: RbRefrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#>( |
| 14 | src: &mut Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<T, Rs>, |
| 15 | dst: &mut Producerrust-analyzer cargo ringbuf 0.3.3 producer/Producer#<T, Rd>, |
| 16 | count: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 17 | ) -> usize |
| 18 | where |
| 19 | Rs::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbReadrust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbRead#<T>, |
| 20 | Rd::Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/RbRef#Rb#: RbWriterust-analyzer cargo ringbuf 0.3.3 ring_buffer/base/RbWrite#<T>, |
| 21 | { |
| 22 | let (src_left, src_right) = unsafe { src.as_uninit_slicesrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]as_uninit_slices().() }; |
| 23 | let (dst_left, dst_right) = unsafe { dst.free_space_as_slicesrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]free_space_as_slices().() }; |
| 24 | let src_iter = src_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().(src_right.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()); |
| 25 | let dst_iter = dst_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().(dst_right.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().()); |
| 26 | |
| 27 | let mut actual_count = 0; |
| 28 | for (src_elem, dst_place) in src_iter.ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(dst_iter) { |
| 29 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(count) = count { |
| 30 | if actual_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().count { |
| 31 | break; |
| 32 | } |
| 33 | } |
| 34 | unsafe { dst_place.writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]write().(src_elem.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_ptr().().readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]read().()) }; |
| 35 | actual_count 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; |
| 36 | } |
| 37 | unsafe { src.advancerust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]advance().(actual_count) }; |
| 38 | unsafe { dst.advancerust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]advance().(actual_count) }; |
| 39 | actual_count |
| 40 | } |