Referring to types of tuple fields

Viewed 225

Is there any way to refer to the types of a tuple's fields without recapitulation? Something along the lines of this:

pub struct Foo(i16, u64);
impl Foo {
    pub fn get_bar(&self) -> Self::0 { self.0 }
    pub fn get_baz(&self) -> Self::1 { self.1 }
}

fn main() {
    let foo = Foo(123, 456);
    println!("bar: {}", foo.get_bar());
    println!("baz: {}", foo.get_baz());
}

(This does not work, because Self::0 isn't a thing. But maybe it is and I just don't know what it's called.)

0 Answers
Related