Hello fellow Rustaceans,
I'm a new-comer to the language and try to wrap my head around the concept of borrowing.
I have the following code that works for me (after reading the rust-book & learning about cloning):
fn update(_app: &App, model: &mut Model, _update: Update) {
let mut messages: Vec<osc::Message> = vec![];
for (packet, _addr) in model.receiver.try_iter() {
packet.unfold(&mut messages)
}
for m in messages.iter() {
match &m.args {
Some(values) => {
for v in values.iter() {
match v.clone().int() {
Some(rssi) => {
model.rssi.push(rssi as u16);
}
_ => {}
}
}
}
_ => {}
}
}
}
Now the error I try to understand is the need to invoke .clone() on the value v
of type
If I look at the method declaration
it appears as if the culprit is the self. Instead of using &self. This makes the call want to take ownership.
Am I correct in assuming that (for this case) one could implement method.int taking a reference as reading the underlying bytes of the OSC message and converting to i32 is actually not something that needs the move?