Skip to content

Commit 6591ca2

Browse files
committed
added patmove example
1 parent 2d464a4 commit 6591ca2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ in a controlled repository now.
1818
* `modules`: example of modules
1919
* `point.rs`: example of "methods" and ownership
2020
* `units.rs`: example of newtype and deriving
21+
* `patmove.rs`: example of `ref` in patterns

patmove.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct Foo {
2+
tuple: (String, u64),
3+
}
4+
5+
impl Foo {
6+
fn is_hello(&self) -> bool {
7+
match self.tuple {
8+
(ref s, _) => {
9+
s == "hello"
10+
}
11+
}
12+
}
13+
}
14+
15+
fn main() {
16+
let t = Foo { tuple: ("hello".to_string(), 1) };
17+
println!("{}", t.is_hello());
18+
}

0 commit comments

Comments
 (0)