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§

§

Borrowed(RSlice<'a, T>)

§

Owned(RVec<T>)

Implementations§

source§

impl<'a, T> RCowSlice<'a, T>

source

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]);
source

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<T: Clone> AsRef<[T]> for RCowSlice<'_, T>

source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Clone> Borrow<[T]> for RCowSlice<'_, T>

source§

fn borrow(&self) -> &[T]

Immutably borrows from an owned value. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a, T> From<&'a [T]> for RCowSlice<'a, T>
where T: Clone,

source§

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

Converts to this type from the input type.
source§

impl<'a, T> From<&'a RVec<T>> for RCowSlice<'a, T>
where T: Clone,

source§

fn from(this: &'a RVec<T>) -> Self

Converts to this type from the input type.
source§

impl<'a, T> From<&'a Vec<T>> for RCowSlice<'a, T>
where T: Clone,

source§

fn from(this: &'a Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<'a, T> From<RSlice<'a, T>> for RCowSlice<'a, T>
where T: Clone,

source§

fn from(this: RSlice<'a, T>) -> Self

Converts to this type from the input type.
source§

impl<'a, T> From<RVec<T>> for RCowSlice<'a, T>
where T: Clone,

source§

fn from(this: RVec<T>) -> Self

Converts to this type from the input type.
source§

impl<'a, T> From<Vec<T>> for RCowSlice<'a, T>
where T: Clone,

source§

fn from(this: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<'a, T: Clone> IntoReprRust for RCowSlice<'a, T>

§

type ReprRust = Cow<'a, [T]>

The #[repr(Rust)] equivalent.
source§

fn into_rust(self) -> Self::ReprRust

Performs the conversion
source§

impl<T, U> PartialEq<&[U]> for RCowSlice<'_, T>
where T: Clone + PartialEq<U>,

source§

fn eq(&self, other: &&[U]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<[U]> for RCowSlice<'_, T>
where T: Clone + PartialEq<U>,

source§

fn eq(&self, other: &[U]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U, const N: usize> PartialEq<[U; N]> for RCowSlice<'_, T>
where T: Clone + PartialEq<U>,

source§

fn eq(&self, other: &[U; N]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<Cow<'_, [U]>> for RCowSlice<'_, T>
where T: Clone + PartialEq<U>, U: Clone,

source§

fn eq(&self, other: &Cow<'_, [U]>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<RSlice<'_, T>> for RCowSlice<'_, U>
where T: Clone, U: Clone + PartialEq<T>,

source§

fn eq(&self, other: &RSlice<'_, T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<RSliceMut<'_, T>> for RCowSlice<'_, U>
where T: Clone, U: Clone + PartialEq<T>,

source§

fn eq(&self, other: &RSliceMut<'_, T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<U, T> PartialEq<RVec<T>> for RCowSlice<'_, U>
where T: Clone, U: Clone + PartialEq<T>,

source§

fn eq(&self, other: &RVec<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<Vec<U>> for RCowSlice<'_, T>
where T: Clone + PartialEq<U>,

source§

fn eq(&self, other: &Vec<U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialOrd<&[U]> for RCowSlice<'_, T>
where T: PartialOrd<U> + Clone, [T]: PartialOrd<[U]>,

source§

fn partial_cmp(&self, other: &&[U]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, U> PartialOrd<[U]> for RCowSlice<'_, T>
where T: PartialOrd<U> + Clone, [T]: PartialOrd<[U]>,

source§

fn partial_cmp(&self, other: &[U]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, U, const N: usize> PartialOrd<[U; N]> for RCowSlice<'_, T>
where T: PartialOrd<U> + Clone, [T]: PartialOrd<[U]>,

source§

fn partial_cmp(&self, other: &[U; N]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, U> PartialOrd<Cow<'_, [U]>> for RCowSlice<'_, T>
where T: PartialOrd<U> + Clone, [T]: PartialOrd<[U]>, U: Clone,

source§

fn partial_cmp(&self, other: &Cow<'_, [U]>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<U, T> PartialOrd<RSlice<'_, T>> for RCowSlice<'_, U>
where U: PartialOrd<T> + Clone, [U]: PartialOrd<[T]>, T: Clone,

source§

fn partial_cmp(&self, other: &RSlice<'_, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<U, T> PartialOrd<RSliceMut<'_, T>> for RCowSlice<'_, U>
where U: PartialOrd<T> + Clone, [U]: PartialOrd<[T]>, T: Clone,

source§

fn partial_cmp(&self, other: &RSliceMut<'_, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<U, T> PartialOrd<RVec<T>> for RCowSlice<'_, U>
where U: PartialOrd<T> + Clone, [U]: PartialOrd<[T]>, T: Clone,

source§

fn partial_cmp(&self, other: &RVec<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, U> PartialOrd<Vec<U>> for RCowSlice<'_, T>
where T: PartialOrd<U> + Clone, [T]: PartialOrd<[U]>,

source§

fn partial_cmp(&self, other: &Vec<U>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more