pub type RCowVal<'a, T> = RCow<&'a T, T>;
Expand description
Ffi-safe equivalent of Cow<'a, T>
, either a &T
or T
.
§Example
use abi_stable::std_types::{RCow, RCowVal};
fn foo(x: u8) -> RCowVal<'static, u8> {
if x % 2 == 0 {
RCow::Borrowed(&1)
} else {
RCow::Owned(x * 2)
}
}
assert_eq!(*foo(3), 6);
assert_eq!(*foo(4), 1);
assert_eq!(*foo(5), 10);
assert_eq!(*foo(6), 1);
assert_eq!(*foo(7), 14);
Aliased Type§
enum RCowVal<'a, T> {
Borrowed(&'a T),
Owned(T),
}
Variants§
Implementations
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 RCowVal<'a, T>where
T: Clone + Deserialize<'de>,
impl<'de, 'a, T> Deserialize<'de> for RCowVal<'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 RCowVal<'a, T>
impl<'a, T: Clone> IntoReprRust for RCowVal<'a, 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.