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