How to de-reference an integer element from enum reference?
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?
Solution 1:
Use the de-reference operator *
.
enum Foo {
X(i32)
}
fn take(foo: &Foo) -> i32 {
match foo {
X(a) => return *a
}
}