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]);
Source§impl<B> RCow<B, B::ROwned>where
B: IntoOwned,
impl<B> RCow<B, B::ROwned>where
B: IntoOwned,
Sourcepub fn to_mut(&mut self) -> &mut B::ROwned
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!"));
Sourcepub fn into_owned(self) -> B::ROwned
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!");
Sourcepub fn borrowed(&self) -> &<B as Deref>::Target
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>
impl<B, O> RCow<B, O>
Sourcepub const fn is_borrowed(&self) -> bool
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());
}
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> PartialOrd<&[U]> for RCowSlice<'_, T>
impl<T, U> PartialOrd<&[U]> for RCowSlice<'_, T>
Source§impl<T, U> PartialOrd<[U]> for RCowSlice<'_, T>
impl<T, U> PartialOrd<[U]> for RCowSlice<'_, T>
Source§impl<T, U, const N: usize> PartialOrd<[U; N]> for RCowSlice<'_, T>
impl<T, U, const N: usize> PartialOrd<[U; N]> for RCowSlice<'_, T>
Source§impl<T, U> PartialOrd<Cow<'_, [U]>> for RCowSlice<'_, T>
impl<T, U> PartialOrd<Cow<'_, [U]>> for RCowSlice<'_, T>
Source§impl<U, T> PartialOrd<RSlice<'_, T>> for RCowSlice<'_, U>
impl<U, T> PartialOrd<RSlice<'_, T>> for RCowSlice<'_, U>
Source§impl<U, T> PartialOrd<RSliceMut<'_, T>> for RCowSlice<'_, U>
impl<U, T> PartialOrd<RSliceMut<'_, T>> for RCowSlice<'_, U>
Source§impl<U, T> PartialOrd<RVec<T>> for RCowSlice<'_, U>
impl<U, T> PartialOrd<RVec<T>> for RCowSlice<'_, U>
Source§impl<T, U> PartialOrd<Vec<U>> for RCowSlice<'_, T>
impl<T, U> PartialOrd<Vec<U>> for RCowSlice<'_, T>
Source§impl<'a, T> From<Cow<'a, T>> for RCow<T::RefC, T::ROwned>where
T: ?Sized + RCowCompatibleRef<'a>,
impl<'a, T> From<Cow<'a, T>> for RCow<T::RefC, T::ROwned>where
T: ?Sized + RCowCompatibleRef<'a>,
Source§impl<B, O> GetStaticEquivalent_ for RCow<B, O>where
B: __StableAbi,
O: __StableAbi,
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>
type StaticEquivalent = _static_RCow<<B as GetStaticEquivalent_>::StaticEquivalent, <O as GetStaticEquivalent_>::StaticEquivalent>
The
'static
equivalent of Self
Source§impl<B> Ord for RCow<B, B::ROwned>
impl<B> Ord for RCow<B, B::ROwned>
Source§impl<B, V> PartialOrd<RCow<V, <V as IntoOwned>::ROwned>> for RCow<B, B::ROwned>
impl<B, V> PartialOrd<RCow<V, <V as IntoOwned>::ROwned>> for RCow<B, B::ROwned>
Source§impl<B, O> StableAbi for RCow<B, O>where
B: __StableAbi,
O: __StableAbi,
impl<B, O> StableAbi for RCow<B, O>where
B: __StableAbi,
O: __StableAbi,
Source§const LAYOUT: &'static TypeLayout = _
const LAYOUT: &'static TypeLayout = _
The layout of the type provided by implementors.
Source§type IsNonZeroType = False
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
Source§const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.