Given a rust `Vec` on a type defined using the newtype idiom, Is there a way to have a slice of the underlying original type?

  Kiến thức lập trình

In other words, if I have defined a type like e.g.

pub struct MyFloat(f64);

is it possible to have something like this?

let v = vec![MyFloat(0.),MyFloat(1.)];
let v_slice_f64 : &[f64] = v.slice_underlying_type();
assert_eq!(v_slice_f64, &[0.,1.]);

This is because I would like to wrap the native f64 with the newtype idiom, but some libraries I use require &[f64] as input argument in their methods.

LEAVE A COMMENT