Thanks! I'd love to find something that works from buffer to buffer. I just figured out Rust Playground, so I can ask more clearly. This shows how ReadBytesExt works now and the comments show how I'd like to use it.
use std::f32;
use std::f64;
use std::io::Cursor;
use byteorder::{BigEndian, ReadBytesExt};
fn main() {
let mut dst32 = [0f32; 2];
let mut rdr = Cursor::new(vec![0x40, 0x49, 0x0f, 0xdb, 0x3f, 0x80, 0x00, 0x00]);
rdr.read_f32_into::<BigEndian>(&mut dst32).unwrap();
assert_eq!([f32::consts::PI, 1.0], dst32);
let mut rdr = Cursor::new(vec![0x40, 0x49, 0x0f, 0xdb, 0x3f, 0x80, 0x00, 0x00]);
rdr.read_f32_into::<BigEndian>(&mut dst32).unwrap();
assert_eq!([f32::consts::PI, 1.0], dst32);
let mut dst64 = [0f64; 2];
let mut rdr = Cursor::new(vec![
0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18, 0x3f, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
]);
rdr.read_f64_into::<BigEndian>(&mut dst64).unwrap();
assert_eq!([f64::consts::PI, 1.0], dst64);
// Can we make a generic read_into that works with f32,f64 destinations?
/*
let mut rdr = Cursor::new(vec![0x40, 0x49, 0x0f, 0xdb, 0x3f, 0x80, 0x00, 0x00]);
rdr.read_into::<BigEndian>(&mut dst32).unwrap(); // ideal
// dst32.read_into::<BigEndian>(rdr).unwrap(); OK, too
assert_eq!([f32::consts::PI, 1.0], dst32);
let mut rdr = Cursor::new(vec![
0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18, 0x3f, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
]);
rdr.read_into::<BigEndian>(&mut dst64).unwrap(); // ideal
// dst64.read_into::<BigEndian>(rdr).unwrap(); OK, too
assert_eq!([f64::consts::PI, 1.0], dst64);
*/
}
(Playground)