Trait EitherRefVariadic

Source
pub trait EitherRefVariadic: VariadicExt + Sealed {
    type UnRefVar: VariadicExt;
    type RefVar: RefVariadic<UnRefVar = Self::UnRefVar, RefVar = Self::RefVar>;
    type MutVar: MutVariadic<UnRefVar = Self::UnRefVar, MutVar = Self::MutVar>;

    // Required methods
    fn mut_to_ref(self) -> Self::RefVar;
    fn unref_ref(&self) -> <Self::UnRefVar as VariadicExt>::AsRefVar<'_>;
}
Expand description

A variadic of either shared references, exclusive references, or both.

Provides the Self::UnRefVar associated type which is the original variadic of owned values.

This is a sealed trait.

Required Associated Types§

Source

type UnRefVar: VariadicExt

The un-referenced variadic. Each item will have one layer of shared references removed.

The inverse of VariadicExt::AsRefVar and VariadicExt::AsMutVar.

let un_ref: <var_type!(&u32, &String, &bool) as EitherRefVariadic>::UnRefVar =
    var_expr!(1_u32, "Hello".to_owned(), false);
Source

type RefVar: RefVariadic<UnRefVar = Self::UnRefVar, RefVar = Self::RefVar>

This type with all exclusive &mut references replaced with shared & references.

Returned by Self::mut_to_ref.

Source

type MutVar: MutVariadic<UnRefVar = Self::UnRefVar, MutVar = Self::MutVar>

This type with all shared & references replaced with exclusive references &mut.

Conversion from & to &mut is generally invalid, so a ref_to_mut() method does not exist.

Required Methods§

Source

fn mut_to_ref(self) -> Self::RefVar

Convert all exclusive (mut) references into shared references: RefVariadic.

let mut original = var_expr!(1_u32, "Hello".to_owned(), false);
let as_mut: var_type!(&mut u32, &mut String, &mut bool) = original.as_mut_var();
let as_ref_1: var_type!(&u32, &String, &bool) = as_mut.mut_to_ref();
let as_ref_2: var_type!(&u32, &String, &bool) = as_ref_1; // Can copy the reference version.
drop((as_ref_1, as_ref_2));
Source

fn unref_ref(&self) -> <Self::UnRefVar as VariadicExt>::AsRefVar<'_>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EitherRefVariadic for ()

Source§

impl<'a, Item, Rest> EitherRefVariadic for (&'a Item, Rest)
where Rest: EitherRefVariadic,

Source§

impl<'a, Item, Rest> EitherRefVariadic for (&'a mut Item, Rest)
where Rest: EitherRefVariadic,

Implementors§