I have a fairly large Rust application, and, as I was scrolling through it, I realized that I had many clone calls. Is it considered evil or at least not best practice to have many calls of clone?If so, what is the idiomatic method of replacing clone?
Here is a startup function for rocket:
#[rkt::launch]
async fn launch() -> _ {
let matches = cli::Cli::parse();
let path = PathBuf::from(matches.path.unwrap_or(fs_utils::get_cwd()));
let port = matches.port;
if !fs_utils::is_file(&path) {
eprintln!("Sorry, the given path is either not available or it is not a directory.");
exit(1);
}
let config = ServConfig {
base_directory: path.clone(),
port,
};
rkt::build()
.configure(
Config::figment()
.merge(("address", "0.0.0.0"))
.merge(("port", config.port))
.merge((Config::LOG_LEVEL, rkt::config::LogLevel::Off)),
)
.manage(Arc::new(Mutex::new(config.clone())))
.attach(log::Logger {})
.register("/", rkt::catchers![not_found, dotfile_attempt])
.mount(
"/",
vec![Route::ranked(10, Get, "/<path..>", CustomHandler())],
)
.mount("/", rkt::routes![assets])
}
Is there any idiomatic method to replace the two clone calls?
2