rust - How to partition Vec in place in method that doesn't own `self`? -
so, there's struct looks this: struct foo { alpha: vec<t>, beta: vec<t>, } and method should move values matches condition alpha beta . question is: clean way without owning self ? the vec::partition() method can't used because moving of self.alpha causes cannot move out of dereference of &mut-pointer compile error. ps: t have file inside doesn't implement clone . do want drop beta ? sort of thing std::mem::replace for, allowing pull out: use std::mem; impl foo { fn munge(&mut self) { let alpha = mem::replace(&mut self.alpha, vec::new()); let (alpha, beta) = alpha.partition(…); self.alpha = alpha; self.beta = beta; } } note there is new vec created there briefly, doesn’t matter; doesn’t involve allocation , cheap. (the alternative leaving uninitialised memory there , replacing again, forgetting uninitialised memory, unsafe if partition can fail run destructor on uninit...