pub type RCowStr<'a> = RCow<RStr<'a>, RString>;
Expand description
Ffi-safe equivalent of Cow<'a, str>
, either an RStr
or RString
.
§Example
use abi_stable::std_types::{RCow, RCowStr};
fn foo(x: &str) -> RCowStr<'_> {
if let Some(x) = x.strip_prefix("tri") {
RCow::from(x.repeat(3))
} else {
RCow::from(x)
}
}
assert_eq!(foo("foo"), "foo");
assert_eq!(foo("bar"), "bar");
assert_eq!(foo("tribaz"), "bazbazbaz");
assert_eq!(foo("triqux"), "quxquxqux");
Aliased Type§
enum RCowStr<'a> {
Borrowed(RStr<'a>),
Owned(RString),
}
Variants§
Implementations§
Source§impl<'a> RCowStr<'a>
impl<'a> RCowStr<'a>
Sourcepub const fn from_str(this: &'a str) -> Self
pub const fn from_str(this: &'a str) -> 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, RCowStr};
const C: RCowStr<'_> = RCow::from_str("hello");
assert_eq!(C, "hello");
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> Deserialize<'de> for RCowStr<'a>
impl<'de, 'a> Deserialize<'de> for RCowStr<'a>
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> IntoReprRust for RCowStr<'a>
impl<'a> IntoReprRust for RCowStr<'a>
Source§impl PartialOrd<&str> for RCowStr<'_>
impl PartialOrd<&str> for RCowStr<'_>
Source§impl PartialOrd<Cow<'_, str>> for RCowStr<'_>
impl PartialOrd<Cow<'_, str>> for RCowStr<'_>
Source§impl PartialOrd<RStr<'_>> for RCowStr<'_>
impl PartialOrd<RStr<'_>> for RCowStr<'_>
Source§impl PartialOrd<RString> for RCowStr<'_>
impl PartialOrd<RString> for RCowStr<'_>
Source§impl PartialOrd<String> for RCowStr<'_>
impl PartialOrd<String> for RCowStr<'_>
Source§impl PartialOrd<str> for RCowStr<'_>
impl PartialOrd<str> for RCowStr<'_>
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.