tupleops/tpl_ref_mut.rs
1crate::do_impl!("ref-mut", tuple_ref_mut, {
2 /// The resulting type when every element of this reference to a mutable tuple is turned into
3 /// a mutable reference.
4 ///
5 /// ```ignore
6 /// use same_types::assert_same_types;
7 /// use tupleops::RefMutTuple;
8 ///
9 /// assert_same_types!(
10 /// RefMutTuple<'a, (u8, u16, u32)>,
11 /// (&'a mut u8, &'a mut u16, &'a mut u32),
12 /// );
13 /// ```
14 ///
15 /// See also: [ref_mut_tuple()], [TupleRefMut].
16 #[cfg_attr(docsrs, doc(cfg(feature = "ref-mut")))]
17 pub type RefMutTuple<'a, Tpl> = <&'a mut Tpl as TupleRefMut<'a, Tpl>>::Type;
18
19 /// Turn a reference to a mutable tuple into a tuple of mutable references.
20 ///
21 /// ```
22 /// use tupleops::ref_mut_tuple;
23 ///
24 /// assert_eq!(
25 /// ref_mut_tuple(&mut (1, 2, 3)),
26 /// (&mut 1, &mut 2, &mut 3),
27 /// );
28 /// ```
29 ///
30 /// See also: [RefMutTuple], [TupleRefMut].
31 #[cfg_attr(docsrs, doc(cfg(feature = "ref-mut")))]
32 #[inline(always)]
33 pub fn ref_mut_tuple<'a, Tpl>(tpl: &'a mut Tpl) -> RefMutTuple<'a, Tpl>
34 where
35 &'a mut Tpl: TupleRefMut<'a, Tpl>,
36 {
37 <&'a mut Tpl as TupleRefMut<'a, Tpl>>::ref_mut_tuple(tpl)
38 }
39
40 /// A reference to a mutable tuple that is usable with [ref_mut_tuple()].
41 ///
42 /// See also: [ref_mut_tuple()], [RefMutTuple].
43 #[cfg_attr(docsrs, doc(cfg(feature = "ref-mut")))]
44 pub trait TupleRefMut<'a, Tpl> {
45 #[doc(hidden)]
46 type Type;
47
48 #[doc(hidden)]
49 fn ref_mut_tuple(tpl: &'a mut Tpl) -> Self::Type;
50 }
51
52 impl<'a> TupleRefMut<'a, ()> for &'a mut () {
53 type Type = ();
54
55 #[inline(always)]
56 fn ref_mut_tuple((): &'a mut ()) -> Self::Type {}
57 }
58});