Struct abi_stable::std_types::RVec [−][src]
#[repr(C)]pub struct RVec<T> { /* fields omitted */ }
Expand description
Ffi-safe equivalent of std::vec::Vec
.
Example
Here is a function that partitions numbers by whether they are even or odd.
use abi_stable::{
std_types::{RSlice,RVec},
StableAbi,
sabi_extern_fn,
};
#[repr(C)]
#[derive(StableAbi)]
pub struct Partitioned{
pub even:RVec<u32>,
pub odd :RVec<u32>,
}
#[sabi_extern_fn]
pub fn partition_evenness(numbers:RSlice<'_,u32>)->Partitioned{
let (even,odd)=numbers.iter().cloned().partition(|n| *n % 2 == 0);
Partitioned{even,odd}
}
Implementations
Creates a new,empty RVec<T>
.
This function does not allocate.
Example
use abi_stable::std_types::RVec;
let list=RVec::<u32>::new();
This returns the amount of elements this RVec can store without reallocating.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::new();
assert_eq!(list.capacity(),0);
list.push(0);
assert_ne!(list.capacity(),0);
Gets a mutable raw pointer to the start of this RVec’s buffer.
Creates a new,empty RVec<T>
,with a capacity of cap
.
This function does not allocate if cap == 0
.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u32>::with_capacity(7);
assert_eq!(list.len(),0);
assert_eq!(list.capacity(),7);
list.extend( std::iter::repeat(11).take(7) );
assert_eq!(list.len(),7);
assert_eq!(list.capacity(),7);
list.push(17);
assert_ne!(list.capacity(),7);
Creates an RSlice<'a,T>
with access to the range
range of
elements of the RVec<T>
.
Example
use abi_stable::std_types::{RSlice,RVec};
let list=RVec::from(vec![0,1,2,3,4,5,6,7,8]);
assert_eq!( list.slice(..), RSlice::from_slice(&[0,1,2,3,4,5,6,7,8]) );
assert_eq!( list.slice(..4), RSlice::from_slice(&[0,1,2,3]) );
assert_eq!( list.slice(4..), RSlice::from_slice(&[4,5,6,7,8]) );
assert_eq!( list.slice(4..7), RSlice::from_slice(&[4,5,6]) );
Creates an RSliceMut<'a,T>
with access to the range
range of
elements of the RVec<T>
.
Example
use abi_stable::std_types::{RSliceMut,RVec};
let mut list=RVec::from(vec![0,1,2,3,4,5,6,7,8]);
assert_eq!( list.slice_mut(..), RSliceMut::from_mut_slice(&mut [0,1,2,3,4,5,6,7,8]) );
assert_eq!( list.slice_mut(..4), RSliceMut::from_mut_slice(&mut [0,1,2,3]) );
assert_eq!( list.slice_mut(4..), RSliceMut::from_mut_slice(&mut [4,5,6,7,8]) );
assert_eq!( list.slice_mut(4..7), RSliceMut::from_mut_slice(&mut [4,5,6]) );
Creates a &[T]
with access to all the elements of the RVec<T>
.
Example
use abi_stable::std_types::RVec;
let list=RVec::from(vec![0,1,2,3]);
assert_eq!(list.as_slice(), &[0,1,2,3]);
Creates a &mut [T]
with access to all the elements of the RVec<T>
.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::from(vec![0,1,2,3]);
assert_eq!(list.as_mut_slice(), &mut [0,1,2,3]);
Creates an RSlice<'_,T>
with access to all the elements of the RVec<T>
.
Example
use abi_stable::std_types::{RSlice,RVec};
let list=RVec::from(vec![0,1,2,3]);
assert_eq!(list.as_rslice(), RSlice::from_slice(&[0,1,2,3]));
Creates an RSliceMut<'_,T>
with access to all the elements of the RVec<T>
.
Example
use abi_stable::std_types::{RSliceMut,RVec};
let mut list=RVec::from(vec![0,1,2,3]);
assert_eq!(list.as_mut_rslice(), RSliceMut::from_mut_slice(&mut [0,1,2,3]));
Returns the amount of elements of the RVec<T>
.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u64>::new();
assert_eq!(list.len(),0);
list.push(0xDEAFBEEF);
assert_eq!(list.len(),1);
list.push(0xCAFE);
assert_eq!(list.len(),2);
Sets the length field of RVec<T>
to new_len
.
Safety
new_len
must be less than or equal to self.capacity()
.
The elements betweem the old length and the new length must be initialized.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u64>::new();
list.reserve_exact(10);
unsafe{
let start=list.as_mut_ptr();
for i in 0..10 {
start.add(i as usize).write(i);
}
list.set_len(10);
}
assert_eq!( list, (0..10).collect::<RVec<u64>>() );
Shrinks the capacity of the RVec
to match its length.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u32>::with_capacity(7);
list.extend( std::iter::repeat(11).take(4) );
assert_eq!(list.len(),4);
assert_eq!(list.capacity(),7);
list.shrink_to_fit();
assert_eq!(list.len(),4);
assert_eq!(list.capacity(),4);
Whether the length of the RVec<T>
is 0.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u64>::new();
assert_eq!(list.is_empty(),true);
list.push(0x1337);
assert_eq!(list.is_empty(),false);
list.push(0xC001);
assert_eq!(list.is_empty(),false);
Converts this RVec<T>
into a Vec<T>
.
Allocation
If this is invoked outside of the dynamic library/binary that created it,
it will allocate a new Vec<T>
and move the data into it.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u64>::new();
list.push(0);
list.push(1);
list.push(2);
assert_eq!(list.into_vec(), vec![0,1,2]);
Creates a Vec<T>
,copying all the elements of this RVec<T>
.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u64>::new();
list.extend( (4..=7).rev() );
assert_eq!(list.to_vec(), vec![7,6,5,4] );
Clones a &[T]
into a new RVec<T>
.
This function was defined to aid type inference,
because eg:&[0,1]
is a &[i32;2]
not a &[i32]
.
Example
use abi_stable::std_types::RVec;
let slic=&[99,88,77,66];
let list=RVec::<u64>::from_slice(slic);
assert_eq!(list.as_slice(),slic);
Attemps to remove the element at index
position,
returns None
if self.len() <= index
.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::from(vec![0,1,2,3]);
assert_eq!(list.try_remove(4),None);
assert_eq!(list.try_remove(3),Some(3));
assert_eq!(list.try_remove(1),Some(1));
assert_eq!(list.as_slice(), &[0,2]);
Removes the element at index
position,
Panic
Panics if self.len() <= index
.
Example
use abi_stable::{
std_types::{RStr,RVec},
traits::IntoReprC,
};
// This type annotation is purely for the reader.
let mut list:RVec<RStr<'static>>=
vec!["foo".into_c(), "bar".into(), "baz".into()].into_c();
assert_eq!( list.remove(2), "baz".into_c() );
assert_eq!(list.as_slice(), &["foo".into_c(), "bar".into_c()] );
assert_eq!( list.remove(0), "foo".into_c() );
assert_eq!(list.as_slice(), &["bar".into_c()] );
Swaps the element at index
position with the last element,and then removes it.
Panic
Panics if self.len() <= index
.
Example
use abi_stable::{
std_types::{RStr,RVec},
traits::IntoReprC,
};
// This type annotation is purely for the reader.
let mut list:RVec<RStr<'static>>=
vec!["foo".into_c(), "bar".into(), "baz".into(), "geo".into()].into_c();
assert_eq!( list.swap_remove(1), "bar".into_c() );
assert_eq!( list.as_slice(), &["foo".into_c(), "geo".into(), "baz".into()] );
assert_eq!( list.swap_remove(0), "foo".into_c() );
assert_eq!( list.as_slice(), &["baz".to_string(), "geo".into()] );
Appends new_val
at the end of the RVec<T>
.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u32>::new();
list.push(11);
assert_eq!(list.as_slice(), &[11]);
list.push(22);
assert_eq!(list.as_slice(), &[11,22]);
list.push(55);
assert_eq!(list.as_slice(), &[11,22,55]);
Attempts to remove the last element,
returns None
if the RVec<T>
is empty.
Example
use abi_stable::std_types::{RSlice,RVec};
let mut list=RVec::<u32>::from_slice(&[11,22,55]);
assert_eq!(list.pop(), Some(55));
assert_eq!(list.as_slice(), &[11,22]);
assert_eq!(list.pop(), Some(22));
assert_eq!(list.as_slice(), &[11]);
assert_eq!(list.pop(), Some(11));
assert_eq!(list.as_rslice(), RSlice::<u32>::EMPTY );
assert_eq!(list.pop(), None);
Truncates the RVec<T>
to to
length.
Does nothing if self.len() <= to
.
Note:this has no effect on the capacity of the RVec<T>
.
Example
use abi_stable::std_types::{RSlice,RVec};
let mut list=RVec::<u32>::from_slice(&[11,22,55,66,77]);
list.truncate(3);
assert_eq!(list.as_slice(), &[11,22,55] );
list.truncate(0);
assert_eq!(list.as_rslice(), RSlice::<u32>::EMPTY );
list.truncate(5555); //This is a no-op.
Removes all the elements from collection.
Note:this has no effect on the capacity of the RVec<T>
.
Example
use abi_stable::std_types::{RSlice,RVec};
let mut list=RVec::<u32>::from_slice(&[11,22,55]);
assert_eq!( list.as_slice(), &[11,22,55] );
list.clear();
assert_eq!( list.as_rslice(), RSlice::<u32>::EMPTY );
assert_ne!( list.capacity(), 0 );
Retains only the elements that satisfy the pred
predicate
This means that a element will be removed if pred(that_element)
returns false.
Example
use abi_stable::std_types::RVec;
{
let mut list=(0..=10).collect::<Vec<u32>>();
list.retain(|x| *x%3 ==0 );
assert_eq!(list.as_slice(), &[0,3,6,9]);
}
{
let mut list=(0..=10).collect::<Vec<u32>>();
list.retain(|x| *x%5 ==0 );
assert_eq!(list.as_slice(), &[0,5,10]);
}
Reserves àdditional
additional capacity for extra elements.
This may reserve more than necessary for the additional capacity.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u32>::new();
list.reserve(10);
assert!( list.capacity()>=10 );
let cap=list.capacity();
list.extend(0..10);
assert_eq!( list.capacity(),cap );
Reserves àdditional
additional capacity for extra elements.
Prefer using reserve
for most situations.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u32>::new();
list.reserve_exact(17);
assert_eq!( list.capacity(),17 );
let cap=list.capacity();
list.extend(0..17);
assert_eq!( list.capacity(),cap );
Resizes the RVec<T>
to new_len
length.
extending the RVec<T>
with clones of value
to reach the new length.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u32>::new();
list.resize(5,88);
assert_eq!( list.as_slice(), &[88,88,88,88,88] );
list.resize(3,0);
assert_eq!( list.as_slice(), &[88,88,88] );
list.resize(6,123);
assert_eq!( list.as_slice(), &[88,88,88,123,123,123] );
Extends this RVec<_>
with clones of the elements of the slice.
Example
use abi_stable::std_types::RVec;
let mut list=RVec::<u64>::new();
list.extend_from_slice(&[99,88]);
list.extend_from_slice(&[77,66]);
assert_eq!( list.as_slice(), &[99,88,77,66] );
Extends this RVec<_>
with copies of the elements of the slice.
Example
use abi_stable::{
std_types::{RStr,RVec},
traits::IntoReprC,
};
let mut list=RVec::<RStr<'_>>::new();
list.extend_from_slice(&["foo".into_c(), "bar".into()]);
list.extend_from_slice(&["baz".into_c(), "goo".into()]);
assert_eq!(
list.as_slice(),
&["foo".into_c(), "bar".into(), "baz".into(), "goo".into()],
);
Creates a draining iterator that removes the specified range in
the RVec<T>
and yields the removed items.
Panic
Panics if the index is out of bounds or if the start of the range is greater than the end of the range.
Consumption
The elements in the range will be removed even if the iterator was dropped before yielding them.
Example
use abi_stable::std_types::{RSlice,RVec};
{
let mut list=RVec::from(vec![0,1,2,3,4,5]);
assert_eq!( list.drain(2..4).collect::<Vec<_>>(), vec![2,3] );
assert_eq!( list.as_slice(), &[0,1,4,5] );
}
{
let mut list=RVec::from(vec![0,1,2,3,4,5]);
assert_eq!( list.drain(2..).collect::<Vec<_>>(), vec![2,3,4,5] );
assert_eq!( list.as_slice(), &[0,1] );
}
{
let mut list=RVec::from(vec![0,1,2,3,4,5]);
assert_eq!( list.drain(..2).collect::<Vec<_>>(), vec![0,1] );
assert_eq!( list.as_slice(), &[2,3,4,5] );
}
{
let mut list=RVec::from(vec![0,1,2,3,4,5]);
assert_eq!( list.drain(..).collect::<Vec<_>>(), vec![0,1,2,3,4,5] );
assert_eq!( list.as_rslice(), RSlice::<u32>::EMPTY );
}
Trait Implementations
Mutably borrows from an owned value. Read more
Deserialize this value from the given Serde deserializer. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
type StaticEquivalent = _static_RVec<__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 RVec<T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
impl<T, U, const N: usize> PartialOrd<[U; N]> for RVec<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 RVec<T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
impl<T, U> PartialOrd<Cow<'_, [U]>> for RVec<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 RVec<T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
impl<T, U> PartialOrd<RCow<'_, [U]>> for RVec<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
impl<T, U> PartialOrd<RSliceMut<'_, U>> for RVec<T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
impl<T, U> PartialOrd<RSliceMut<'_, U>> for RVec<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
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<RVec<T>> for RSliceMut<'_, U> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
impl<U, T> PartialOrd<RVec<T>> for RSliceMut<'_, 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
impl<U, T, const N: usize> PartialOrd<RVec<T>> for [U; N] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
impl<U, T, const N: usize> PartialOrd<RVec<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<RVec<T>> for Cow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
impl<U, T> PartialOrd<RVec<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<RVec<T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
impl<U, T> PartialOrd<RVec<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
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 RVec<T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
impl<T, U> PartialOrd<Vec<U, Global>> for RVec<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
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.
Write a buffer into this writer, returning how many bytes were written. Read more
Attempts to write an entire buffer into this writer. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for RVec<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for RVec<T> where
T: RefUnwindSafe + UnwindSafe,
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.