Reputation: 105043
This is my code:
enum Foo {
X(i32)
}
fn take(foo: &Foo) -> i32 {
match foo {
X(a) => return a
}
}
I'm getting:
6 | X(a) => return a,
| ^^^^ expected `i32`, found `&i32`
What is the right way?
Upvotes: 0
Views: 61
Reputation: 12463
Use the de-reference operator *
.
enum Foo {
X(i32)
}
fn take(foo: &Foo) -> i32 {
match foo {
X(a) => return *a
}
}
Upvotes: 1