unwrap_or
followed by a function call RS-W1031unwrap_or
followed by function call, prefer unwrap_or_else
instead 95 translate: bool,
96 timeout: Option<Duration>,
97 ) -> Result<String, ModelError> {
98 let timeout = timeout.unwrap_or(Duration::from_secs(30)); 99 debug!(%self.session_id, %self.peer_address, "getting result from stts");
100 // send the finalize message
101 self.tx
Calls to unwrap_or
followed by a function call should be replaced with
unwrap_or_else
or unwrap_or_default
, to increase laziness. The argument to
unwrap_or
is evaluated eagerly and unconditionally. unwrap_or_else
or
unwrap_or_default
are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.
Replace the call to unwrap_or
with unwrap_or_else
or unwrap_or_default
.
// allocates a new `Foo` instance even if `bar` is `Ok(_)`
bar.unwrap_or(Foo::new());
// only allocates if `bar` evaluates to `Err(_)`
bar.unwrap_or_else(|| Foo::new());