tuplities_ref/lib.rs
1#![no_std]
2
3//! [tuplities](https://github.com/lucacappelletti94/tuplities) suite crate providing the `TupleRef` trait.
4
5#[tuplities_derive::impl_tuple_ref]
6/// A trait for tuples that provides a method to get a tuple of references.
7///
8/// This trait provides both an associated type `Ref<'a>` that represents a tuple
9/// of references to the elements, and a method `tuple_ref` that returns such a tuple.
10///
11/// # Examples
12///
13/// ```rust
14/// use tuplities_ref::TupleRef;
15///
16/// let tuple = (1, "hello".to_string(), vec![1, 2, 3]);
17/// let refs = tuple.tuple_ref();
18/// assert_eq!(refs, (&1, &"hello".to_string(), &vec![1, 2, 3]));
19/// ```
20pub trait TupleRef {
21 /// The type of a tuple containing references to each element.
22 type Ref<'a>
23 where
24 Self: 'a;
25
26 /// Returns a tuple of references to each element.
27 ///
28 /// # Examples
29 ///
30 /// ```rust
31 /// use tuplities_ref::TupleRef;
32 ///
33 /// let tuple = (42, "world");
34 /// let refs = tuple.tuple_ref();
35 /// assert_eq!(refs, (&42, &"world"));
36 /// ```
37 fn tuple_ref(&self) -> Self::Ref<'_>;
38}