abi_stable::std_types::cow

Type Alias 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 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])
Source§

impl<B> RCow<B, B::ROwned>
where B: IntoOwned,

Source

pub fn to_mut(&mut self) -> &mut B::ROwned

Get a mutable reference to the owned form of RCow, converting to the owned form if it is currently the borrowed form.

§Examples
use abi_stable::std_types::{RCow, RCowStr};

let mut cow: RCowStr<'_> = RCow::from("Hello");

assert_eq!(&*cow, "Hello");
assert!(cow.is_borrowed());

cow.to_mut().push_str(", world!");

assert!(cow.is_owned());
assert_eq!(cow, RCow::from("Hello, world!"));
Source

pub fn into_owned(self) -> B::ROwned

Unwraps into the owned owner form of RCow, converting to the owned form if it is currently the borrowed form.

§Examples
use abi_stable::std_types::{RCow, RCowStr};

let mut cow: RCowStr<'_> = RCow::from("Hello");

assert_eq!(&*cow, "Hello");

let mut buff = cow.into_owned();
buff.push_str(", world!");

assert_eq!(&*buff, "Hello, world!");
Source

pub fn borrowed(&self) -> &<B as Deref>::Target

Gets the contents of the RCow casted to the borrowed variant.

§Examples
use abi_stable::std_types::{RCow, RCowSlice, RSlice};
{
    let cow: RCowSlice<'_, u8> = RCow::from(&[0, 1, 2, 3][..]);
    assert_eq!(cow.borrowed(), RSlice::from_slice(&[0, 1, 2, 3]));
}
{
    let cow: RCowSlice<'_, u8> = RCow::from(vec![0, 1, 2, 3]);
    assert_eq!(cow.borrowed(), RSlice::from_slice(&[0, 1, 2, 3]));
}
Source§

impl<B, O> RCow<B, O>

Source

pub const fn is_borrowed(&self) -> bool

Whether this is a borrowing RCow.

§Examples
use abi_stable::std_types::{RCow, RCowSlice};

{
    let cow: RCowSlice<'_, u8> = RCow::from(&[0, 1, 2, 3][..]);
    assert!(cow.is_borrowed());
}
{
    let cow: RCowSlice<'_, u8> = RCow::from(vec![0, 1, 2, 3]);
    assert!(!cow.is_borrowed());
}
Source

pub const fn is_owned(&self) -> bool

Whether this is an owning RCow.

§Examples
use abi_stable::std_types::{RCow, RCowSlice};

let cow: RCowSlice<'_, u8> = RCow::from(&[0, 1, 2, 3][..]);
assert!(!cow.is_owned());

let cow: RCowSlice<'_, u8> = RCow::from(vec![0, 1, 2, 3]);
assert!(cow.is_owned());

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>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B> Clone for RCow<B, B::ROwned>
where B: IntoOwned, B::ROwned: Clone,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B> Debug for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B> Deref for RCow<B, B::ROwned>
where B: IntoOwned,

Source§

type Target = <B as Deref>::Target

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<B> Display for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T> From<Cow<'a, T>> for RCow<T::RefC, T::ROwned>
where T: ?Sized + RCowCompatibleRef<'a>,

Source§

fn from(this: Cow<'a, T>) -> RCow<T::RefC, T::ROwned>

Converts to this type from the input type.
Source§

impl<B, O> GetStaticEquivalent_ for RCow<B, O>
where B: __StableAbi, O: __StableAbi,

Source§

type StaticEquivalent = _static_RCow<<B as GetStaticEquivalent_>::StaticEquivalent, <O as GetStaticEquivalent_>::StaticEquivalent>

The 'static equivalent of Self
Source§

impl<B> Hash for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Hash,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<B> Ord for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<B, V> PartialEq<RCow<V, <V as IntoOwned>::ROwned>> for RCow<B, B::ROwned>
where B: IntoOwned, V: IntoOwned, B::Target: PartialEq<V::Target>,

Source§

fn eq(&self, other: &RCow<V, V::ROwned>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<B, V> PartialOrd<RCow<V, <V as IntoOwned>::ROwned>> for RCow<B, B::ROwned>
where B: IntoOwned, V: IntoOwned, B::Target: PartialOrd<V::Target>,

Source§

fn partial_cmp(&self, other: &RCow<V, V::ROwned>) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B> Serialize for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<B, O> StableAbi for RCow<B, O>
where B: __StableAbi, O: __StableAbi,

Source§

const LAYOUT: &'static TypeLayout = _

The layout of the type provided by implementors.
Source§

type IsNonZeroType = False

Whether this type has a single invalid bit-pattern. Read more
Source§

const ABI_CONSTS: AbiConsts = _

const-equivalents of the associated types.
Source§

impl<B> Copy for RCow<B, B::ROwned>
where B: IntoOwned, B::ROwned: Copy,

Source§

impl<B> Eq for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Eq,