Struct inout::inout_buf::InOutBuf

source ·
pub struct InOutBuf<'inp, 'out, T> {
    pub(crate) in_ptr: *const T,
    pub(crate) out_ptr: *mut T,
    pub(crate) len: usize,
    pub(crate) _pd: PhantomData<(&'inp T, &'out mut T)>,
}
Expand description

Custom slice type which references one immutable (input) slice and one mutable (output) slice of equal length. Input and output slices are either the same or do not overlap.

Fields§

§in_ptr: *const T§out_ptr: *mut T§len: usize§_pd: PhantomData<(&'inp T, &'out mut T)>

Implementations§

source§

impl<'a, T> InOutBuf<'a, 'a, T>

source

pub fn from_mut(val: &'a mut T) -> InOutBuf<'a, 'a, T>

Create InOutBuf from a single mutable reference.

source§

impl<'inp, 'out, T> InOutBuf<'inp, 'out, T>

source

pub fn from_ref_mut(in_val: &'inp T, out_val: &'out mut T) -> Self

Create InOutBuf from a pair of immutable and mutable references.

source

pub fn new( in_buf: &'inp [T], out_buf: &'out mut [T], ) -> Result<Self, NotEqualError>

Create InOutBuf from immutable and mutable slices.

Returns an error if length of slices is not equal to each other.

source

pub fn len(&self) -> usize

Get length of the inner buffers.

source

pub fn is_empty(&self) -> bool

Returns true if the buffer has a length of 0.

source

pub fn get<'a>(&'a mut self, pos: usize) -> InOut<'a, 'a, T>

Returns InOut for given position.

§Panics

If pos greater or equal to buffer length.

source

pub fn get_in<'a>(&'a self) -> &'a [T]

Get input slice.

source

pub fn get_out<'a>(&'a mut self) -> &'a mut [T]

Get output slice.

source

pub fn into_out(self) -> &'out mut [T]

Consume self and return output slice with lifetime 'a.

source

pub fn into_raw(self) -> (*const T, *mut T)

Get raw input and output pointers.

source

pub fn reborrow<'a>(&'a mut self) -> InOutBuf<'a, 'a, T>

Reborrow self.

source

pub unsafe fn from_raw( in_ptr: *const T, out_ptr: *mut T, len: usize, ) -> InOutBuf<'inp, 'out, T>

Create InOutBuf from raw input and output pointers.

§Safety

Behavior is undefined if any of the following conditions are violated:

  • in_ptr must point to a properly initialized value of type T and must be valid for reads for len * mem::size_of::<T>() many bytes.
  • out_ptr must point to a properly initialized value of type T and must be valid for both reads and writes for len * mem::size_of::<T>() many bytes.
  • in_ptr and out_ptr must be either equal or non-overlapping.
  • If in_ptr and out_ptr are equal, then the memory referenced by them must not be accessed through any other pointer (not derived from the return value) for the duration of lifetime ’a. Both read and write accesses are forbidden.
  • If in_ptr and out_ptr are not equal, then the memory referenced by out_ptr must not be accessed through any other pointer (not derived from the return value) for the duration of lifetime ’a. Both read and write accesses are forbidden. The memory referenced by in_ptr must not be mutated for the duration of lifetime 'a, except inside an UnsafeCell.
  • The total size len * mem::size_of::<T>() must be no larger than isize::MAX.
source

pub fn split_at( self, mid: usize, ) -> (InOutBuf<'inp, 'out, T>, InOutBuf<'inp, 'out, T>)

Divides one buffer into two at mid index.

The first will contain all indices from [0, mid) (excluding the index mid itself) and the second will contain all indices from [mid, len) (excluding the index len itself).

§Panics

Panics if mid > len.

source

pub fn into_chunks<N: ArrayLength<T>>( self, ) -> (InOutBuf<'inp, 'out, GenericArray<T, N>>, InOutBuf<'inp, 'out, T>)

Partition buffer into 2 parts: buffer of arrays and tail.

source§

impl<'inp, 'out> InOutBuf<'inp, 'out, u8>

source

pub fn xor_in2out(&mut self, data: &[u8])

XORs data with values behind the input slice and write result to the output slice.

§Panics

If data length is not equal to the buffer length.

Trait Implementations§

source§

impl<'a, T> From<&'a mut [T]> for InOutBuf<'a, 'a, T>

source§

fn from(buf: &'a mut [T]) -> Self

Converts to this type from the input type.
source§

impl<'inp, 'out, T> IntoIterator for InOutBuf<'inp, 'out, T>

§

type Item = InOut<'inp, 'out, T>

The type of the elements being iterated over.
§

type IntoIter = InOutBufIter<'inp, 'out, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'inp, 'out, T, N> TryInto<InOut<'inp, 'out, GenericArray<T, N>>> for InOutBuf<'inp, 'out, T>
where N: ArrayLength<T>,

§

type Error = IntoArrayError

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<InOut<'inp, 'out, GenericArray<T, N>>, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'inp, 'out, T> Freeze for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> RefUnwindSafe for InOutBuf<'inp, 'out, T>
where T: RefUnwindSafe,

§

impl<'inp, 'out, T> !Send for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> !Sync for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> Unpin for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> !UnwindSafe for InOutBuf<'inp, 'out, T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.