pub trait AsTuple<'a> {
type Tuple;
type TupleMut;
fn as_tuple(&'a self) -> Self::Tuple;
fn as_tuple_mut(&'a mut self) -> Self::TupleMut;
}
Expand description
A trait for viewing a struct as a tuple. You shouldn’t implement this yourself, since the point of this crate is to derive it for you.
Examples
use as_tuple::AsTuple;
#[derive(AsTuple)]
struct Position {
x: f32,
y: f32,
}
let mut position = Position { x: 6.2, y: 4.3 };
{
let (x, y) = position.as_tuple_mut();
*x -= 1.0;
*y += 1.0;
}
assert_eq!(position.x, 5.2);
assert_eq!(position.y, 5.3);
Remarks
The tuple contains a reference to every field, so you’ll often have references to references.
Don’t attempt to derive this on an enum or a union, since um… it won’t work.
Required Associated Types§
Required Methods§
sourcefn as_tuple(&'a self) -> Self::Tuple
fn as_tuple(&'a self) -> Self::Tuple
Gets a tuple containing immutable references to every field of the struct.
sourcefn as_tuple_mut(&'a mut self) -> Self::TupleMut
fn as_tuple_mut(&'a mut self) -> Self::TupleMut
Gets a tuple containing mutable references to every field of the struct.