Skip to main content

TupleExt

Trait TupleExt 

Source
pub trait TupleExt: Sized {
    type Left;
    type Right;
    type Pack<T>;

    // Required methods
    fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
       where Self::Right: Into<D>;
    fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
       where Self::Left: Into<D>;
}
Expand description

Chain call assigns tuple elements to outside

§Examples

use right_as::TupleExt;

let mut right = "";
let left = "left,right"
    .split_once(',')
    .unwrap()
    .right_as(&mut right);

assert_eq!(left, "left");
assert_eq!(right, "right");
use right_as::TupleExt;

let [b, c] = &mut [0; 2];
let a = Some(1)
    .zip(Some(2))
    .zip(Some(3))
    .right_as(c)
    .right_as(b);

assert_eq!(a, Some(1));
assert_eq!(b, &mut 2);
assert_eq!(c, &mut 3);
use right_as::TupleExt;

let mut right = None;
let left = "left,right"
    .split_once(',')
    .unwrap()
    .right_as(&mut right);

assert_eq!(left, "left");
assert_eq!(right, Some("right"));
use right_as::TupleExt;

let mut right = "";
let left = "left,right"
    .split_once(',')
    .right_as(&mut right);

assert_eq!(left, Some("left"));
assert_eq!(right, "right");
use right_as::TupleExt;

let mut right = "";
let left = "left"
    .split_once(',')
    .right_as(&mut right);

assert_eq!(left, None);
assert_eq!(right, "");

Required Associated Types§

Required Methods§

Source

fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
where Self::Right: Into<D>,

Like {*to = self.1.into(); self.0}

Source

fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
where Self::Left: Into<D>,

Like {*to = self.0.into(); self.1}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<L, R, E> TupleExt for Result<(L, R), E>

Source§

type Left = L

Source§

type Right = R

Source§

type Pack<T> = Result<T, E>

Source§

fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
where Self::Right: Into<D>,

Source§

fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
where Self::Left: Into<D>,

Source§

impl<L, R> TupleExt for (L, R)

Source§

type Left = L

Source§

type Right = R

Source§

type Pack<T> = T

Source§

fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
where Self::Right: Into<D>,

Source§

fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
where Self::Left: Into<D>,

Source§

impl<L, R> TupleExt for Option<(L, R)>

Source§

type Left = L

Source§

type Right = R

Source§

type Pack<T> = Option<T>

Source§

fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
where Self::Right: Into<D>,

Source§

fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
where Self::Left: Into<D>,

Source§

impl<L> TupleExt for [L; 2]

Source§

type Left = L

Source§

type Right = L

Source§

type Pack<T> = T

Source§

fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
where Self::Right: Into<D>,

Source§

fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
where Self::Left: Into<D>,

Implementors§