-
-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Description
I believe I'm doing this correctly. I'm trying to create an f64 from 4 u16s.
extern crate byteorder;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
// hello
fn main() {
let mut cursor = std::io::Cursor::new(vec![]);
cursor.write_u16::<LittleEndian>(0u16).unwrap();
cursor.write_u16::<LittleEndian>(1u16).unwrap();
cursor.write_u16::<LittleEndian>(2u16).unwrap();
cursor.write_u16::<LittleEndian>(3u16).unwrap();
println!("{:?}", cursor);
let f = cursor.read_f64::<LittleEndian>().unwrap();
println!("{}", f);
}My println outputs Cursor { inner: [0, 0, 1, 0, 2, 0, 3, 0], pos: 8 }, but the read_f64 line panics with:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: UnexpectedEof, error: StringError
("failed to fill whole buffer") }', libcore/result.rs:945:5
Am I doing something wrong? 8 x 8 = 64, so I believe the cursor has the correct number of bytes in it. I see no reason why this would be erroring in this way.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels