Type Alias abi_stable::std_types::RCowStr
source · 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");
sourcepub const fn as_str(&self) -> &str
pub const fn as_str(&self) -> &str
Borrows this RCow as a str.
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_str("world");
assert_eq!(cow.as_str(), "world")
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 PartialEq<&str> for RCowStr<'_>
impl PartialEq<&str> for RCowStr<'_>
source§impl PartialEq<Cow<'_, str>> for RCowStr<'_>
impl PartialEq<Cow<'_, str>> for RCowStr<'_>
source§impl PartialEq<RStr<'_>> for RCowStr<'_>
impl PartialEq<RStr<'_>> for RCowStr<'_>
source§impl PartialEq<RString> for RCowStr<'_>
impl PartialEq<RString> for RCowStr<'_>
source§impl PartialEq<String> for RCowStr<'_>
impl PartialEq<String> for RCowStr<'_>
source§impl PartialOrd<&str> for RCowStr<'_>
impl PartialOrd<&str> for RCowStr<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<Cow<'_, str>> for RCowStr<'_>
impl PartialOrd<Cow<'_, str>> for RCowStr<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<RStr<'_>> for RCowStr<'_>
impl PartialOrd<RStr<'_>> for RCowStr<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<RString> for RCowStr<'_>
impl PartialOrd<RString> for RCowStr<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<String> for RCowStr<'_>
impl PartialOrd<String> for RCowStr<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl PartialOrd<str> for RCowStr<'_>
impl PartialOrd<str> for RCowStr<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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