1pub trait TupleUnwrap<T> {
2 fn tuple_into(self) -> T;
3}
4
5impl<T> TupleUnwrap<T> for T {
6 fn tuple_into(self) -> T {
7 self
8 }
9}
10
11
12impl<T> TupleUnwrap<T> for (T,) {
13 fn tuple_into(self) -> T {
14 self.0
15 }
16}
17
18#[cfg(test)]
19mod tests {
20 use super::*;
21
22 #[test]
23 fn identity_impl() {
24 let x = 42;
25 let y = 42;
26 let s = "Hello!";
27
28 let _x: i32 = x.tuple_into();
29 let _y: u32 = y.tuple_into();
30 let _s = s.tuple_into();
31 }
32
33 #[test]
34 fn tuple_impl() {
35 let x = (42,);
36 let y = (42,);
37 let s = ("Hello!",);
38
39 let _x: i32 = x.tuple_into();
40 let _y: u32 = y.tuple_into();
41 let _s: &str = s.tuple_into();
42 }
43}