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/// ```
23///
24/// Part of the [`tuplities`](https://docs.rs/tuplities/latest/tuplities/) crate.
25pub trait TupleMut {
26 /// The type of a tuple containing mutable references to each element.
27 type Mut<'a>
28 where
29 Self: 'a;
30
31 /// Returns a tuple of mutable references to each element.
32 ///
33 /// # Examples
34 ///
35 /// ```rust
36 /// use tuplities_mut::TupleMut;
37 ///
38 /// let mut tuple = (42, "world".to_string());
39 /// let mut_refs = tuple.tuple_mut();
40 /// *mut_refs.0 = 24;
41 /// mut_refs.1.make_ascii_uppercase();
42 /// assert_eq!(tuple, (24, "WORLD".to_string()));
43 /// ```
44 fn tuple_mut(&mut self) -> Self::Mut<'_>;
45}