misc: clippy: add needless_pass_by_value (partially)

This helps to uncover expensive and needless clones in the code base.
For example, I prevented extensive clones in the snapshot path where
(nested) BTreeMap's have been cloned over and over again. Further,
the lint helps devs to much better reason about the ownership of
parameters.

All of these changes have been done manually with the necessary
caution. A few structs that are cheap to clone are now `copy` so that
this lint won't trigger for them.

I didn't enable the lint so far as it is a massive rabbit hole and
needs much more fixes. Nevertheless, it is very useful.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster 2025-11-25 14:29:36 +01:00 committed by Rob Bradford
parent 0a07c96d17
commit 6a86c157af
29 changed files with 162 additions and 155 deletions

View file

@ -86,7 +86,7 @@ impl Emulator {
///
/// * `path` - A path to the Unix Domain Socket swtpm is listening on
///
pub fn new(path: String) -> Result<Self> {
pub fn new(path: &str) -> Result<Self> {
if !Path::new(&path).exists() {
return Err(Error::InitializeEmulator(anyhow!(
"The input TPM Socket path: {path:?} does not exist"

View file

@ -58,8 +58,8 @@ impl SocketDev {
}
}
pub fn init(&mut self, path: String) -> Result<()> {
self.connect(&path)?;
pub fn init(&mut self, path: &str) -> Result<()> {
self.connect(path)?;
Ok(())
}