15 Self(1,2) // Self as a constructor
20 Self(x, y) => println!("{} {}", x, y), // Self as a pattern
25 struct ST2<T>(T); // With type parameter
27 impl<T> ST2<T> where T: Display {
29 fn ctor(v: T) -> Self {
35 Self(ref v) => println!("{}", v),
40 struct ST3<'a>(&'a i32); // With lifetime parameter
44 fn ctor(v: &'a i32) -> Self {
49 let Self(ref v) = self;
57 fn map(opt: Option<usize>) -> Option<Self> {
58 opt.map(Self) // use `Self` as a function passed somewhere
62 struct ST5; // unit struct
66 Self // `Self` as a unit struct value
69 fn pattern(self) -> Self {
71 Self => Self, // `Self` as a unit struct value for matching
84 let Self(_x) = match self { Self(x) => Self(x) };
85 let _opt: Option<Self> = Some(0).map(Self);
89 struct ST7<T1, T2>(T1, T2);
91 impl ST7<i32, usize> {
97 fn pattern(self) -> Self {
99 Self(x, y) => Self(x, y),
105 let v1 = ST1::ctor();
108 let v2 = ST2::ctor(10);
112 let v3 = ST3::ctor(&local);
115 let v4 = Some(1usize);
116 let _ = ST4::map(v4);
118 let v5 = ST5::ctor();
121 let v6 = ST6::ctor();
124 let v7 = ST7::<i32, usize>::ctor();
125 let r = v7.pattern();
126 println!("{} {}", r.0, r.1)