Type Alias abi_stable::std_types::RCowSlice
source · pub type RCowSlice<'a, T> = RCow<RSlice<'a, T>, RVec<T>>;
Expand description
Ffi-safe equivalent of Cow<'a, [T]>
, either an RSlice
or RVec
.
Example
use abi_stable::std_types::{RCow, RCowSlice, RVec};
use std::iter::once;
fn foo(x: &[u32]) -> RCowSlice<'_, u32> {
match x {
[prev @ .., x] if *x == 5 => RCow::from(RVec::from(prev)),
_ => RCow::from(x),
}
}
assert_eq!(foo(&[3, 4]), &[3, 4][..]);
assert_eq!(foo(&[3, 4, 5]), &[3, 4][..]);
assert_eq!(foo(&[3, 4, 5, 6]), &[3, 4, 5, 6][..]);
assert_eq!(foo(&[3, 4, 5, 6, 7]), &[3, 4, 5, 6, 7][..]);
Aliased Type§
enum RCowSlice<'a, T> {
Borrowed(RSlice<'a, T>),
Owned(RVec<T>),
}
Variants§
Implementations§
source§impl<'a, T> RCowSlice<'a, T>
impl<'a, T> RCowSlice<'a, T>
sourcepub const fn from_slice(this: &'a [T]) -> Self
pub const fn from_slice(this: &'a [T]) -> Self
For converting a &'a [T]
to an RCowSlice<'a, T>
,
most useful when converting from &'a [T;N]
because it coerces the array to a slice.
Example
use abi_stable::std_types::{RCow, RCowSlice};
const C: RCowSlice<'_, u8> = RCow::from_slice(&[3, 5, 8]);
assert_eq!(C, [3, 5, 8]);
sourcepub const fn as_slice(&self) -> &[T]
pub const fn as_slice(&self) -> &[T]
Borrows this RCow as a slice.
Conditional const fn
This function requires the rust_1_64
feature to be const
-callable
Example
use abi_stable::std_types::RCow;
let cow = RCow::from_slice(&[3, 5, 8]);
assert_eq!(cow.as_slice(), [3, 5, 8])
Trait Implementations§
source§impl<'de, 'a, T> Deserialize<'de> for RCowSlice<'a, T>where
T: Clone + Deserialize<'de>,
impl<'de, 'a, T> Deserialize<'de> for RCowSlice<'a, T>where
T: Clone + Deserialize<'de>,
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<'a, T: Clone> IntoReprRust for RCowSlice<'a, T>
impl<'a, T: Clone> IntoReprRust for RCowSlice<'a, T>
source§impl<T, U> PartialEq<&[U]> for RCowSlice<'_, T>
impl<T, U> PartialEq<&[U]> for RCowSlice<'_, T>
source§impl<T, U, const N: usize> PartialEq<[U; N]> for RCowSlice<'_, T>
impl<T, U, const N: usize> PartialEq<[U; N]> for RCowSlice<'_, T>
source§impl<T, U> PartialEq<Cow<'_, [U]>> for RCowSlice<'_, T>
impl<T, U> PartialEq<Cow<'_, [U]>> for RCowSlice<'_, T>
source§impl<U, T> PartialEq<RSlice<'_, T>> for RCowSlice<'_, U>
impl<U, T> PartialEq<RSlice<'_, T>> for RCowSlice<'_, U>
source§impl<U, T> PartialEq<RSliceMut<'_, T>> for RCowSlice<'_, U>
impl<U, T> PartialEq<RSliceMut<'_, T>> for RCowSlice<'_, U>
source§impl<U, T> PartialEq<RVec<T>> for RCowSlice<'_, U>
impl<U, T> PartialEq<RVec<T>> for RCowSlice<'_, U>
source§impl<T, U> PartialEq<Vec<U>> for RCowSlice<'_, T>
impl<T, U> PartialEq<Vec<U>> for RCowSlice<'_, T>
source§impl<T, U> PartialOrd<&[U]> for RCowSlice<'_, T>
impl<T, U> PartialOrd<&[U]> for RCowSlice<'_, T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T, U> PartialOrd<[U]> for RCowSlice<'_, T>
impl<T, U> PartialOrd<[U]> for RCowSlice<'_, T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T, U, const N: usize> PartialOrd<[U; N]> for RCowSlice<'_, T>
impl<T, U, const N: usize> PartialOrd<[U; N]> for RCowSlice<'_, T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T, U> PartialOrd<Cow<'_, [U]>> for RCowSlice<'_, T>
impl<T, U> PartialOrd<Cow<'_, [U]>> for RCowSlice<'_, T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<U, T> PartialOrd<RSlice<'_, T>> for RCowSlice<'_, U>
impl<U, T> PartialOrd<RSlice<'_, T>> for RCowSlice<'_, U>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<U, T> PartialOrd<RSliceMut<'_, T>> for RCowSlice<'_, U>
impl<U, T> PartialOrd<RSliceMut<'_, T>> for RCowSlice<'_, U>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<U, T> PartialOrd<RVec<T>> for RCowSlice<'_, U>
impl<U, T> PartialOrd<RVec<T>> for RCowSlice<'_, U>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T, U> PartialOrd<Vec<U>> for RCowSlice<'_, T>
impl<T, U> PartialOrd<Vec<U>> for RCowSlice<'_, T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more