I have a function doing that for a int:
fn some_to_value(src: Option<&int>) -> Option<int> {
match src {
Some(x) => Some(*x),
None => None
}
}
and I wanted to make it generic (and still use it with an "int" at the level of the caller). It would be ok for me if the instance of T is copied. So I tried with that:
fn some_to_value<T>(src: Option<&T>) -> Option<T> {
match src {
Some(x) => Some(*x),
None => None
}
}
I get:
error: cannot move out of dereference of `&`-pointer
Some(x) => Some(*x),
^~
I fail to understand why it fails (I'm a beginner).
Some context: I made a copy of an Option, because I realized that after doing a "find" on a "HashMap", the map will be immutable as long as the return of the "find" (an Option containing a reference to an item of the map) is alive.