pub trait TupleStructure<TupleKind: RefTypes> {
    fn get_ref(&self) -> TupleKind::Ref<'_>;
    fn get_mut(&mut self) -> TupleKind::Mut<'_>;
    fn new(t: TupleKind::Owned) -> Self;
}
Expand description

Trait for types that have the same shape as tuples, such as tuples and structs.

For example, the tuple (A, B) implements TupleStructure<Tuple2<A, B>> since it is a 2-tuple with fields of type A and B. The struct S { a: A, b: B } also implements TupleStructure<Tuple2<A, B>>.

We can then write generic functions over both (A, B) and S using this trait.

  • self.get_ref() returns immutable references to each of their fields (e.g. (&A, &B))
  • self.get_mut() returns mutable references to each of their fields (e.g. (&mut A, &mut B))
  • Self::new(..) creates a new Self from a list of its fields (e.g. Self::new((a, b)))

Required Methods

Implementations on Foreign Types

Implementors