Type Alias abi_stable::std_types::cow::RCowVal

source ·
pub type RCowVal<'a, T> = RCow<&'a T, T>;
Expand description

Ffi-safe equivalent of Cow<'a, T>, either a &T or T.

Example

use abi_stable::std_types::{RCow, RCowVal};

fn foo(x: u8) -> RCowVal<'static, u8> {
    if x % 2 == 0 {
       RCow::Borrowed(&1)
    } else {
       RCow::Owned(x * 2)
    }
}

assert_eq!(*foo(3), 6);
assert_eq!(*foo(4), 1);
assert_eq!(*foo(5), 10);
assert_eq!(*foo(6), 1);
assert_eq!(*foo(7), 14);

Aliased Type§

enum RCowVal<'a, T> {
    Borrowed(&'a T),
    Owned(T),
}

Variants§

§

Borrowed(&'a T)

§

Owned(T)

Trait Implementations§

source§

impl<T: Clone> AsRef<T> for RCowVal<'_, T>

source§

fn as_ref(&self) -> &T

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

impl<T: Clone> Borrow<T> for RCowVal<'_, T>

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<'de, 'a, T> Deserialize<'de> for RCowVal<'a, T>
where T: Clone + Deserialize<'de>,

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, T: Clone> IntoReprRust for RCowVal<'a, T>

§

type ReprRust = Cow<'a, T>

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

fn into_rust(self) -> Self::ReprRust

Performs the conversion