Destructuring problem
pub struct ModelInfo {
pub obj_reg: ObjReg, // <- struct typre
pub metainfo: Box<MetaInfoProvider>, // <- box of a trait
pub obj_pool: ObjPool, // <- struct type
pub str_int: StrInt, // <- struct type
}
impl ModelInfo {
pub fn merge(mut self, o: Self) -> Self {
let Self { mut str_int, mut obj_reg, mut metainfo, mut obj_pool } = o;
for (sym, s) in str_int.into_iter() { // into_iter consumes self
}
self
}
}
How is this even possible?
error[E0507]: cannot move out of borrowed content
|
201 | for (sym, s) in str_int.into_iter() {
| ^^^^^^^ cannot move out of borrowed content
As I understand, content is not borrowed but moved here. What am I missing?
Posted Apr 23, 2018, 3:56 PM UTC · edited
29
What are all the types here? any chance you can give a playpen showing the error?
I've added the struct type. Unfortunately, it is a part of a huge app and I can't disclose the source code. I thought that it is maybe kind of an obvious mistake.
It happens. I, at least, won't be able to sort it without the types.
https://play.rust-lang.org/?gist=b1b197e553d9b56b17fbd6e5dab0944b&version=stable
What's the intoiterator look like?
Oh, I think I found the problem, this code involves Deref and it returns a reference. Thank you!
Great!
Ah, so
StrIntdoesn't implementIntoIterator, but derefs to something that does?[deleted]