You can use slice::last
:
fn top(&mut self) -> Option<f64> {
self.last().copied()
}
Option::copied
(and Option::cloned
) can be used to convert from an Option<&f64>
to an Option<f64>
, matching the desired function signature.
You can also remove the mut
from both the implementation and the trait definition.