Here I have an struct with some references to borrowed items, and I want to put a copy of it in a HashMap, using insert. So I use to_owned, which ought to give me a clean ownable copy I can pass to HashMap. That should just work; I paid for an allocation and a copy. But the compiler complains the result of to_owned is not assignable. How can it not be? That's the whole point of to_owned, right? " The ToOwned
trait generalizes Clone
to construct owned data from any borrow of a given type."
The error message also complains that types don't match and yet lists "expected" and "found" as identical.
The HashMap involved is defined by
pub waiting_for_handle: HashMap<LLUUID, PendingHandle<'a>>,
and here's the error:
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> src/viewer/world.rs:96:15
|
96 | match ms {
| ^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the method body at 94:5...
--> src/viewer/world.rs:94:5
|
94 | pub fn handlemessage(&self, ms: &AllMessages) -> Result<(), StrError> { // incoming message
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the types are compatible
--> src/viewer/world.rs:96:15
|
96 | match ms {
| ^^
= note: expected `&generateddefs::AllMessages<'_>`
found `&generateddefs::AllMessages<'_>`
note: but, the lifetime must be valid for the lifetime `'_` as defined on the impl at 75:12...
--> src/viewer/world.rs:75:12
|
75 | impl World<'_> {
| ^^
note: ...so that the expression is assignable
--> src/viewer/world.rs:138:68
|
138 | ... self.pending.waiting_for_handle.insert(id, PendingHandle{timestamp: timestamp(), handshake: ownedhandshake}.to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `PendingHandle<'_>`
found `PendingHandle<'_>`