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