Trait named_tup::TupInto

source ·
pub trait TupInto<T>: Sealed {
    // Required method
    fn into_tup(self) -> T;
}
Expand description

A copy of the Into trait from the standard library. The Into trait could unfortunately not be used due to it’s type reflexivity which clashed with the Tup implementation.

This trait is sealed as it should only ever be implemented on the Tup type.

A Tup can be transformed to another type if for all arguments it falls in one of the following categories:

#[tup_default]
pub fn main() {
    let unused_to_unused: Tup!(bar: () = ()) = tup!().into_tup();
    assert_eq!(unused_to_unused, tup!());

    let used_to_used: Tup!(foo: i32) = tup!(foo: 3).into_tup();
    assert_eq!(used_to_used, tup!(foo: 3));

    let used_to_default: Tup!(foo: &'static str = "hi") = tup!(foo: "yum").into_tup();
    assert_eq!(used_to_default, tup!(foo: "yum"));

    let unused_to_default: Tup!(foo: f64 = 1.3) = tup!().into_tup();
    assert_eq!(unused_to_default, tup!(foo: 1.3));

    let default_to_used: Tup!(foo: f64) = unused_to_default.into_tup();
    assert_eq!(default_to_used, tup!(foo: 1.3));
}

Since each rule acts individually on the tup’s arguments we can combine them together.

let colour = tup!(red: 65, green: 105, blue: 225);
let pixel = tup!(x: 5.0, y: 6.4, height: 4.7);

paint(pixel.into_tup(), colour.into_tup());

#[tup_default]
fn paint(pixel: Tup!(x: f64, y: f64, height: f64 = 1.0, width: f64 = 1.0),
         colour: Tup!(red: i32, green: i32, blue: i32, opacity: f64 = 1.0))
{
    let pixel_colour = pixel + colour;
    // Paint    
}

Required Methods§

source

fn into_tup(self) -> T

Performs the conversion.

Implementors§

source§

impl<T, U> TupInto<U> for Twhere U: TupFrom<T>, T: Sealed,