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
trait TupleUnwrap<T> {
fn tuple_into(self) -> T;
}
impl<T> TupleUnwrap<T> for T {
fn tuple_into(self) -> T {
self
}
}
impl<T> TupleUnwrap<T> for (T,) {
fn tuple_into(self) -> T {
self.0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn identity_impl() {
let x = 42;
let y = 42;
let s = "Hello!";
let _x: i32 = x.tuple_into();
let _y: u32 = y.tuple_into();
let _s = s.tuple_into();
}
#[test]
fn tuple_impl() {
let x = (42,);
let y = (42,);
let s = ("Hello!",);
let _x: i32 = x.tuple_into();
let _y: u32 = y.tuple_into();
let _s: &str = s.tuple_into();
}
}