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§

§

Borrowed(RStr<'a>)

§

Owned(RString)

Implementations§

source§

impl<'a> RCowStr<'a>

source

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

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 AsRef<str> for RCowStr<'_>

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<str> for RCowStr<'_>

source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
source§

impl<'de, 'a> Deserialize<'de> for RCowStr<'a>

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> From<&'a RString> for RCowStr<'a>

source§

fn from(this: &'a RString) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a String> for RCowStr<'a>

source§

fn from(this: &'a String) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for RCowStr<'a>

source§

fn from(this: &'a str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<RStr<'a>> for RCowStr<'a>

source§

fn from(this: RStr<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<RString> for RCowStr<'a>

source§

fn from(this: RString) -> Self

Converts to this type from the input type.
source§

impl<'a> From<String> for RCowStr<'a>

source§

fn from(this: String) -> Self

Converts to this type from the input type.
source§

impl<'a> IntoReprRust for RCowStr<'a>

§

type ReprRust = Cow<'a, str>

The #[repr(Rust)] equivalent.
source§

fn into_rust(self) -> Self::ReprRust

Performs the conversion
source§

impl PartialEq<&str> for RCowStr<'_>

source§

fn eq(&self, other: &&str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Cow<'_, str>> for RCowStr<'_>

source§

fn eq(&self, other: &Cow<'_, str>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RStr<'_>> for RCowStr<'_>

source§

fn eq(&self, other: &RStr<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RString> for RCowStr<'_>

source§

fn eq(&self, other: &RString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for RCowStr<'_>

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<str> for RCowStr<'_>

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<&str> for RCowStr<'_>

source§

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<Cow<'_, str>> for RCowStr<'_>

source§

fn partial_cmp(&self, other: &Cow<'_, str>) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<RStr<'_>> for RCowStr<'_>

source§

fn partial_cmp(&self, other: &RStr<'_>) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<RString> for RCowStr<'_>

source§

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<String> for RCowStr<'_>

source§

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<str> for RCowStr<'_>

source§

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more