right-as 0.1.0

Chain call assigns tuple elements to outside
Documentation
#![no_std]
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
pub trait TupleExt: Sized {
    type Left;
    type Right;
    type Pack<T>;

    /// Like `{*to = self.1.into(); self.0}`
    fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
    where Self::Right: Into<D>;

    /// Like `{*to = self.0.into(); self.1}`
    fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
    where Self::Left: Into<D>;
}
impl<L, R> TupleExt for (L, R) {
    type Left = L;
    type Right = R;
    type Pack<T> = T;

    fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
    where Self::Right: Into<D>,
    {
        *to = self.1.into();
        self.0
    }

    fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
    where Self::Left: Into<D>,
    {
        *to = self.0.into();
        self.1
    }
}
impl<L> TupleExt for [L; 2] {
    type Left = L;
    type Right = L;
    type Pack<T> = T;

    fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
    where Self::Right: Into<D>,
    {
        let [left, right] = self;
        *to = right.into();
        left
    }

    fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
    where Self::Left: Into<D>,
    {
        let [left, right] = self;
        *to = left.into();
        right
    }
}
impl<L, R> TupleExt for Option<(L, R)> {
    type Left = L;
    type Right = R;
    type Pack<T> = Option<T>;

    fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
    where Self::Right: Into<D>,
    {
        self.map(|x| x.right_as(to))
    }

    fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
    where Self::Left: Into<D>,
    {
        self.map(|x| x.left_as(to))
    }
}
impl<L, R, E> TupleExt for Result<(L, R), E> {
    type Left = L;
    type Right = R;
    type Pack<T> = Result<T, E>;

    fn right_as<D>(self, to: &mut D) -> Self::Pack<Self::Left>
    where Self::Right: Into<D>,
    {
        self.map(|x| x.right_as(to))
    }

    fn left_as<D>(self, to: &mut D) -> Self::Pack<Self::Right>
    where Self::Left: Into<D>,
    {
        self.map(|x| x.left_as(to))
    }
}