Struct abi_stable::std_types::RSlice [−][src]
#[repr(C)]pub struct RSlice<'a, T> { /* fields omitted */ }
Expand description
Ffi-safe equivalent of &'a [T]
As of the writing this documentation the abi stability of &[T]
is
not yet guaranteed.
Lifetime problems
Because RSlice
dereferences into a slice,you can call slice methods on it.
If you call a slice method that returns a borrow into the slice,
it will have the lifetime of the let slice: RSlice<'a,[T]>
variable instead of the 'a
lifetime that it’s parameterized over.
To get a slice with the same lifetime as an RSlice
,
one must use the RSlice::as_slice
method.
Example of what would not work:
use abi_stable::std_types::RSlice;
fn into_slice<'a,T>(slic:RSlice<'a,T>)->&'a [T] {
&*slic
}
Example of what would work:
use abi_stable::std_types::RSlice;
fn into_slice<'a,T>(slic:RSlice<'a,T>)->&'a [T] {
slic.as_slice()
}
Example
Defining an extern fn that returns a reference to the first element that compares equal to a parameter.
use abi_stable::{
std_types::RSlice,
sabi_extern_fn,
};
#[sabi_extern_fn]
pub fn find_first_mut<'a,T>(slice_:RSlice<'a,T>,element:&T)->Option<&'a T>
where
T:std::cmp::PartialEq
{
slice_.iter()
.position(|x| x==element )
.map(|i| &slice_.as_slice()[i] )
}
Implementations
Constructs an RSlice<'a,T>
from a pointer to the first element,
and a length.
Safety
Callers must ensure that:
-
ptr_
points to valid memory, -
ptr_ .. ptr+len
range is accessible memory. -
ptr_
is aligned toT
. -
The data
ptr_
points to must be valid for the'a
lifetime.
Examples
This function unsafely converts a &[T]
to an RSlice<T>
,
equivalent to doing RSlice::from_slice
.
use abi_stable::std_types::RSlice;
fn convert<T>(slice_:&[T])->RSlice<'_,T>{
unsafe{
RSlice::from_raw_parts( slice_.as_ptr(), slice_.len() )
}
}
Creates an &'a [T]
with access to all the elements of this slice.
Example
use abi_stable::std_types::RSlice;
assert_eq!(RSlice::from_slice(&[0,1,2,3]).as_slice(), &[0,1,2,3]);
The length (in elements) of this slice.
Example
use abi_stable::std_types::RSlice;
assert_eq!(RSlice::<u8>::from_slice(&[]).len(), 0);
assert_eq!(RSlice::from_slice(&[0]).len(), 1);
assert_eq!(RSlice::from_slice(&[0,1]).len(), 2);
Converts a reference to T
to a single element RSlice<'a,T>
.
Note:this function does not copy anything.
Example
use abi_stable::std_types::RSlice;
assert_eq!(RSlice::from_ref(&0), RSlice::from_slice(&[0]) );
assert_eq!(RSlice::from_ref(&1), RSlice::from_slice(&[1]) );
assert_eq!(RSlice::from_ref(&2), RSlice::from_slice(&[2]) );
Converts a &[T]
to an RSlice<'_,T>
.
Example
use abi_stable::std_types::RSlice;
let empty:&[u8]=&[];
assert_eq!(RSlice::<u8>::from_slice(&[]).as_slice(), empty);
assert_eq!(RSlice::from_slice(&[0]).as_slice() , &[0][..]);
assert_eq!(RSlice::from_slice(&[0,1]).as_slice() , &[0,1][..]);
Creates an RSlice<'a,T>
with access to the range
range of elements.
This is an inherent method instead of an implementation of the
std::ops::Index
trait because it does not return a reference.
Example
use abi_stable::std_types::RSlice;
let slic=RSlice::from_slice(&[0,1,2,3]);
assert_eq!(slic.slice(..),RSlice::from_slice(&[0,1,2,3]));
assert_eq!(slic.slice(..2),RSlice::from_slice(&[0,1]));
assert_eq!(slic.slice(2..),RSlice::from_slice(&[2,3]));
assert_eq!(slic.slice(1..3),RSlice::from_slice(&[1,2]));
Creates a new RVec<T>
and clones all the elements of this slice into it.
Example
use abi_stable::std_types::{RSlice,RVec};
let slic=RSlice::from_slice(&[0,1,2,3]);
assert_eq!( slic.slice(..).to_rvec(), RVec::from_slice(&[0,1,2,3]) );
assert_eq!( slic.slice(..2).to_rvec(), RVec::from_slice(&[0,1]) );
assert_eq!( slic.slice(2..).to_rvec(), RVec::from_slice(&[2,3]) );
assert_eq!( slic.slice(1..3).to_rvec(), RVec::from_slice(&[1,2]) );
Trait Implementations
Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Tells this buffer that amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read more
🔬 This is a nightly-only experimental API. (buf_read_has_data_left
)
recently added
Check if the underlying Read
has any data left to be read. Read more
Read all bytes into buf
until the delimiter byte
or EOF is reached. Read more
Read all bytes until a newline (the 0xA
byte) is reached, and append
them to the provided buffer. Read more
Returns an iterator over the contents of this reader split on the byte
byte
. Read more
Deserialize this value from the given Serde deserializer. Read more
type StaticEquivalent = _static_RSlice<'static, __GetStaticEquivalent<T>>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U, const N: usize> PartialOrd<[U; N]> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
impl<T, U, const N: usize> PartialOrd<[U; N]> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<Cow<'_, [U]>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
impl<T, U> PartialOrd<Cow<'_, [U]>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<RCow<'_, [U]>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
impl<T, U> PartialOrd<RCow<'_, [U]>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T, const N: usize> PartialOrd<RSlice<'_, T>> for [U; N] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
impl<U, T, const N: usize> PartialOrd<RSlice<'_, T>> for [U; N] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RSlice<'_, T>> for Cow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
impl<U, T> PartialOrd<RSlice<'_, T>> for Cow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RSlice<'_, T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
impl<U, T> PartialOrd<RSlice<'_, T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<RSlice<'_, U>> for RSliceMut<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
impl<T, U> PartialOrd<RSlice<'_, U>> for RSliceMut<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RSliceMut<'_, T>> for RSlice<'_, U> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
impl<U, T> PartialOrd<RSliceMut<'_, T>> for RSlice<'_, U> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<Vec<U, Global>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
impl<T, U> PartialOrd<Vec<U, Global>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Read the exact number of bytes required to fill buf
. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
read_initializer
)Determines if this Read
er can work with buffers of uninitialized
memory. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Creates a “by reference” adapter for this instance of Read
. Read more
Creates an adapter which will chain this stream with another. Read more
type IsNonZeroType = False
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
The layout of the type provided by implementors.
const
-equivalents of the associated types.
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for RSlice<'a, T> where
T: RefUnwindSafe,
impl<'a, T> UnwindSafe for RSlice<'a, T> where
T: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type ROwned = T
type ROwned = T
The owned type, stored in RCow::Owned
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
Compares the address of self
with the address of other
. Read more
Emulates the pipeline operator, allowing method syntax in more places. Read more
The same as piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more
The same as piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read more
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Performs a conversion with Into
.
using the turbofish .into_::<_>()
syntax. Read more
Performs a reference to reference conversion with AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more
Performs a mutable reference to mutable reference conversion with AsMut
,
using the turbofish .as_mut_::<_>()
syntax. Read more
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
Converts a mutable reference back to the original type.
Converts a box back to the original type.
Converts an Arc back to the original type. Read more
Converts an Rc back to the original type. Read more
Converts a value back to the original type.
Converts a reference back to the original type.
Converts a mutable reference back to the original type.
Converts a box back to the original type.
Converts an Arc back to the original type.
Converts an Rc back to the original type.