It's hard to answer exactly without seeing the rest of the code; in cases like this, it can be useful to provide a short, self-contained, correct example of the behavior that you're seeing to make it easier to talk about a concrete issue. In the Rust world, it can be really helpful to trim your problem down to the minimum that can be used to reproduce it on the Playpen, since that makes it very easy for someone else to run it, fix it, and show you the fixed version.
In general, the error that you're getting is because you are moving values. Moving a value means that the function passing the value in is giving up ownership of it, to the function that it is calling. After doing so, the function that passed the value in can no longer use it, because the function that it passed it to may have deallocated it, may have done things to invalidate pointers into it, or any number of other things.
The particular error that you are getting says "use of partially moved value: self
". This indicates to me that you probably moved out one of the components of self before calling your paint_interval()
method. For example, something like this; I've removed the parameters and return values that don't play a part in this example to make it simpler (playpen):
struct Internal;
impl Internal {
fn manipulate(self) {}
}
struct Paintable {
a: Internal,
b: Internal,
}
impl Paintable {
fn paint(self) {
self.a.manipulate();
self.b.manipulate();
}
}
fn main() {
let p = Paintable{ a: Internal, b: Internal };
p.paint()
}
Each of those calls to manipulate
consumes the object that is part of the self
in the paint
method, so after the first one, self
is considered to be a partially moved value; it no longer has ownership of the first Internal
object, so only the second one can still be used, and ownership of the entire Paintable
cannot be transferred. For instance, factoring out that second call reproduces your error (playpen):
impl Paintable {
fn paint(self) {
self.a.manipulate();
self.paint_internal()
}
fn paint_internal(self) {
self.b.manipulate();
}
}
How would you solve this problem? There are a few choices. One is to have manipulate
take self
by reference, rather than by value. Then it doesn't consume a part of the Paintable
, so you can continue to use it later (playpen):
impl Internal {
fn manipulate(&self) {}
}
Or if Internal
is a simple value type, that should just be copied when you pass it into something like manipulate
, you could have it implement Copy
, so manipulate
will just get a copy of it and the original copy will still be valid (playpen):
#[derive(Copy, Clone)]
struct Internal;
Note that if the problem is what I think it is based on the error, the suggestion that @chriskrycho makes about making paint_internal
take &mut self
won't work, because the self
value is still partially moved, and you can't pass a reference to a partially moved object into a function. His suggestion would only work if you were getting an error about self
being moved in the // And some other code
portion that happens after self.paint_internal()
, but in that case you would get an error about use of a moved value rather than use of a partially moved value, such as the following (playpen):
fn paint(self) {
self.paint_internal();
self.a.manipulate();
}
This subtle difference is why I recommend include a complete, but minimal, example that demonstrates the error, as it's easy to misdiagnose a problem without full information.