Enum abi_stable::std_types::RCow [−][src]
#[repr(C)]
pub enum RCow<'a, B> where
B: BorrowOwned<'a> + ?Sized, {
Borrowed(<B as BorrowOwned<'a>>::RBorrowed),
Owned(<B as BorrowOwned<'a>>::ROwned),
}
Expand description
Ffi-safe equivalent of std::borrow::Cow
.
The most common examples of this type are:
-
RCow<'_, str>
: contains anRStr<'_>
or anRString
. -
RCow<'_, [T]>
: contains anRSlice<'_, T>
or anRVec<T>
. -
RCow<'_, T>
: contains a&T
or aT
.
Example
Using a RCow<'a, str>
.
This implements a solution to the well known fizzbuzz problem.
use abi_stable::std_types::RCow;
fn fizzbuzz(n: u32) -> RCow<'static, str> {
match (n % 3, n % 5) {
(0, 0) => RCow::from("FizzBuzz"),
(0, _) => RCow::from("Fizz"),
(_, 0) => RCow::from("Buzz"),
(_, _) => RCow::from(n.to_string()),
}
}
for n in 1..=100 {
println!("{}", fizzbuzz(n));
}
Note: this example allocates when the number is neither a multiple of 5 or 3.
Variants
Borrowed(<B as BorrowOwned<'a>>::RBorrowed)
Tuple Fields of Borrowed
0: <B as BorrowOwned<'a>>::RBorrowed
Owned(<B as BorrowOwned<'a>>::ROwned)
Tuple Fields of Owned
0: <B as BorrowOwned<'a>>::ROwned
Implementations
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;
let mut cow: RCow<'_, str> = 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!"));
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;
let mut cow: RCow<'_, str> = RCow::from("Hello");
assert_eq!(&*cow, "Hello");
let mut buff = cow.into_owned();
buff.push_str(", world!");
assert_eq!(&*buff, "Hello, world!");
Gets the contents of the RCow casted to the borrowed variant.
Examples
use abi_stable::std_types::{RCow, RSlice};
{
let cow: RCow<'_, [u8]> = RCow::from(&[0, 1, 2, 3][..]);
assert_eq!(cow.borrowed(), RSlice::from_slice(&[0, 1, 2, 3]));
}
{
let cow: RCow<'_, [u8]> = RCow::from(vec![0, 1, 2, 3]);
assert_eq!(cow.borrowed(), RSlice::from_slice(&[0, 1, 2, 3]));
}
Whether this is a borrowing RCow.
Examples
use abi_stable::std_types::RCow;
{
let cow: RCow<'_, [u8]> = RCow::from(&[0, 1, 2, 3][..]);
assert!(cow.is_borrowed());
}
{
let cow: RCow<'_, [u8]> = RCow::from(vec![0, 1, 2, 3]);
assert!(!cow.is_borrowed());
}
For converting a &'a [T]
to an RCow<'a, [T]>
,
most useful when converting from &'a [T;N]
because it coerces the array to a slice.
Trait Implementations
Deserialize this value from the given Serde deserializer. Read more
Deserialize this value from the given Serde deserializer. Read more
Deserialize this value from the given Serde deserializer. Read more
impl<'a, B> GetStaticEquivalent_ for RCow<'a, B> where
B: BorrowOwned<'a> + ?Sized,
B: __GetStaticEquivalent_,
<B as BorrowOwned<'a>>::RBorrowed: StableAbi,
<B as BorrowOwned<'a>>::ROwned: StableAbi,
impl<'a, B> GetStaticEquivalent_ for RCow<'a, B> where
B: BorrowOwned<'a> + ?Sized,
B: __GetStaticEquivalent_,
<B as BorrowOwned<'a>>::RBorrowed: StableAbi,
<B as BorrowOwned<'a>>::ROwned: StableAbi,
type StaticEquivalent = _static_RCow<'static, __GetStaticEquivalent<B>>
impl<T, U> PartialOrd<&'_ [U]> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
impl<T, U> PartialOrd<&'_ [U]> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U, const N: usize> PartialOrd<[U; N]> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
impl<T, U, const N: usize> PartialOrd<[U; N]> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<[U]> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
impl<T, U> PartialOrd<[U]> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RCow<'_, [T]>> for Vec<U> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
impl<U, T> PartialOrd<RCow<'_, [T]>> for Vec<U> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RCow<'_, [T]>> for [U] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
impl<U, T> PartialOrd<RCow<'_, [T]>> for [U] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RCow<'_, [T]>> for &[U] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
impl<U, T> PartialOrd<RCow<'_, [T]>> for &[U] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T, const N: usize> PartialOrd<RCow<'_, [T]>> for [U; N] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
impl<U, T, const N: usize> PartialOrd<RCow<'_, [T]>> for [U; N] where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<RCow<'_, [U]>> for RSliceMut<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
impl<T, U> PartialOrd<RCow<'_, [U]>> for RSliceMut<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<RCow<'_, [U]>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
impl<T, U> PartialOrd<RCow<'_, [U]>> for RSlice<'_, T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<RCow<'_, [U]>> for RVec<T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
impl<T, U> PartialOrd<RCow<'_, [U]>> for RVec<T> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<'a, B> PartialOrd<RCow<'a, B>> for RCow<'a, B> where
B: PartialOrd,
B: BorrowOwned<'a> + ?Sized,
impl<'a, B> PartialOrd<RCow<'a, B>> for RCow<'a, B> where
B: PartialOrd,
B: BorrowOwned<'a> + ?Sized,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RSlice<'_, T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
impl<U, T> PartialOrd<RSlice<'_, T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RSliceMut<'_, T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
impl<U, T> PartialOrd<RSliceMut<'_, T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<U, T> PartialOrd<RVec<T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
impl<U, T> PartialOrd<RVec<T>> for RCow<'_, [U]> where
U: PartialOrd<T>,
[U]: PartialOrd<[T]>,
T: Clone,
U: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T, U> PartialOrd<Vec<U, Global>> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
impl<T, U> PartialOrd<Vec<U, Global>> for RCow<'_, [T]> where
T: PartialOrd<U>,
[T]: PartialOrd<[U]>,
T: Clone,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<'a, B> StableAbi for RCow<'a, B> where
B: BorrowOwned<'a> + ?Sized,
B: __GetStaticEquivalent_,
<B as BorrowOwned<'a>>::RBorrowed: StableAbi,
<B as BorrowOwned<'a>>::ROwned: StableAbi,
impl<'a, B> StableAbi for RCow<'a, B> where
B: BorrowOwned<'a> + ?Sized,
B: __GetStaticEquivalent_,
<B as BorrowOwned<'a>>::RBorrowed: StableAbi,
<B as BorrowOwned<'a>>::ROwned: StableAbi,
type IsNonZeroType = False
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
The layout of the type provided by implementors.
const
-equivalents of the associated types.
Auto Trait Implementations
impl<'a, B: ?Sized> RefUnwindSafe for RCow<'a, B> where
<B as BorrowOwned<'a>>::RBorrowed: RefUnwindSafe,
<B as BorrowOwned<'a>>::ROwned: RefUnwindSafe,
impl<'a, B: ?Sized> Send for RCow<'a, B> where
<B as BorrowOwned<'a>>::RBorrowed: Send,
<B as BorrowOwned<'a>>::ROwned: Send,
impl<'a, B: ?Sized> Sync for RCow<'a, B> where
<B as BorrowOwned<'a>>::RBorrowed: Sync,
<B as BorrowOwned<'a>>::ROwned: Sync,
impl<'a, B: ?Sized> Unpin for RCow<'a, B> where
<B as BorrowOwned<'a>>::RBorrowed: Unpin,
<B as BorrowOwned<'a>>::ROwned: Unpin,
impl<'a, B: ?Sized> UnwindSafe for RCow<'a, B> where
<B as BorrowOwned<'a>>::RBorrowed: UnwindSafe,
<B as BorrowOwned<'a>>::ROwned: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type ROwned = T
type ROwned = T
The owned type, stored in RCow::Owned
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
Compares the address of self
with the address of other
. Read more
Emulates the pipeline operator, allowing method syntax in more places. Read more
The same as piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more
The same as piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read more
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Performs a conversion with Into
.
using the turbofish .into_::<_>()
syntax. Read more
Performs a reference to reference conversion with AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more
Performs a mutable reference to mutable reference conversion with AsMut
,
using the turbofish .as_mut_::<_>()
syntax. Read more
Returns the previous character boundary, stopping at 0. Read more
Returns the next character boundary. Read more
Returns the closest characted boundary left of index
(including index
). Read more
Returns the closest characted boundary right of index
(including index
). Read more
fn split_while<P, T>(&'a self, mapper: P) -> SplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
fn split_while<P, T>(&'a self, mapper: P) -> SplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
Returns an iterator over substrings whose characters were mapped to
the same key by mapper
. Read more
fn rsplit_while<P, T>(&'a self, mapper: P) -> RSplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
fn rsplit_while<P, T>(&'a self, mapper: P) -> RSplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
A variation of split_while
that iterates
from the right(the order of substrings is reversed). Read more
The byte index of the nth
character Read more
The byte index of the nth
character Read more
Returns a string containing the first n
chars. Read more
Returns a string containing the last n
chars Read more
Returns the string from the n
th character Read more
Returns the length of the string in utf16 Read more
Returns the character at the at_byte
index inside of the string,
returning None
if the index is outside the string. Read more
Returns an iterator over (index,char) pairs up to
(but not including) the char at the to
byte. Read more
Returns an iterator over (index, char) pairs, starting from the from
byte. Read more
alloc
only.Pads the string on the left with how_much
additional spaces. Read more
Returns a value that pads the string on the left with how_much
additional
spaces in its Display
impl. Read more
core_str_methods
or crate feature alloc
only.The indentation of the first line. Read more
core_str_methods
or crate feature alloc
only.The minimum indentation of the string, ignoring lines that only contain whitespace. Read more
core_str_methods
or crate feature alloc
only.The maximum indentation of the string, ignoring lines that only contain whitespace. Read more
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
Converts a value back to the original type.
Converts a reference back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
alloc
only.Converts an Arc back to the original type.
alloc
only.Converts an Rc back to the original type.