abi_stable::std_types

Type Alias 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 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")
Source§

impl<B> RCow<B, B::ROwned>
where B: IntoOwned,

Source

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!"));
Source

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!");
Source

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>

Source

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());
}
Source

pub const fn is_owned(&self) -> bool

Whether this is an owning RCow.

§Examples
use abi_stable::std_types::{RCow, RCowSlice};

let cow: RCowSlice<'_, u8> = RCow::from(&[0, 1, 2, 3][..]);
assert!(!cow.is_owned());

let cow: RCowSlice<'_, u8> = RCow::from(vec![0, 1, 2, 3]);
assert!(cow.is_owned());

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>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B> Clone for RCow<B, B::ROwned>
where B: IntoOwned, B::ROwned: Clone,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B> Debug for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B> Deref for RCow<B, B::ROwned>
where B: IntoOwned,

Source§

type Target = <B as Deref>::Target

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<B> Display for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T> From<Cow<'a, T>> for RCow<T::RefC, T::ROwned>
where T: ?Sized + RCowCompatibleRef<'a>,

Source§

fn from(this: Cow<'a, T>) -> RCow<T::RefC, T::ROwned>

Converts to this type from the input type.
Source§

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>

The 'static equivalent of Self
Source§

impl<B> Hash for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Hash,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<B> Ord for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<B, V> PartialEq<RCow<V, <V as IntoOwned>::ROwned>> for RCow<B, B::ROwned>
where B: IntoOwned, V: IntoOwned, B::Target: PartialEq<V::Target>,

Source§

fn eq(&self, other: &RCow<V, V::ROwned>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<B, V> PartialOrd<RCow<V, <V as IntoOwned>::ROwned>> for RCow<B, B::ROwned>
where B: IntoOwned, V: IntoOwned, B::Target: PartialOrd<V::Target>,

Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B> Serialize for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<B, O> StableAbi for RCow<B, O>
where B: __StableAbi, O: __StableAbi,

Source§

const LAYOUT: &'static TypeLayout = _

The layout of the type provided by implementors.
Source§

type IsNonZeroType = False

Whether this type has a single invalid bit-pattern. Read more
Source§

const ABI_CONSTS: AbiConsts = _

const-equivalents of the associated types.
Source§

impl<B> Copy for RCow<B, B::ROwned>
where B: IntoOwned, B::ROwned: Copy,

Source§

impl<B> Eq for RCow<B, B::ROwned>
where B: IntoOwned, B::Target: Eq,