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