I am checking Clippy findings in my code and found that the pedantic rule needless_pass_by_value
might be a false positive.
It says that:
warning: this argument is passed by value, but not consumed in the function body
help: consider taking a reference instead:
&Arc<Mutex<MyStruct>>
Since cloning the Arc
is only reference counting, moving the Arc
should not be bad idea. Does it really make any difference in terms of quality and performance to send a reference instead of a value for the Arc
?
#![warn(clippy::pedantic)]
use std::sync::{Arc, Mutex};
fn main() {
let my_struct = MyStruct { value: 3 };
let arc = Arc::new(Mutex::new(my_struct));
arc_taker(arc.clone());
}
fn arc_taker(prm: Arc<Mutex<MyStruct>>) {
prm.lock().unwrap().do_something();
}
struct MyStruct {
value: i32,
}
impl MyStruct {
fn do_something(&self) {
println!("self.value: {}", self.value);
}
}