Accessing the last element of a Vec or a slice

You can use slice::last:

fn top(&mut self) -> Option<f64> {

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.

Leave a Comment