BurntSushi / BurntSushi/byteorder

improve byteorder docs for ReadBytesExt/WriteBytesExt

Open
#130 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.1k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

I believe I'm doing this correctly. I'm trying to create an f64 from 4 u16s.
```rust
extern crate byteorder;

use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};

// hello
fn main() {
let mut cursor = std::io::Cursor::new(vec![]);
cursor.write_u16::(0u16).unwrap();
cursor.write_u16::(1u16).unwrap();
cursor.write_u16::(2u16).unwrap();
cursor.write_u16::(3u16).unwrap();

println!("{:?}", cursor);

let f = cursor.read_f64::().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.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names the ReadBytesExt and WriteBytesExt traits and includes a Rust reproduction; start by reading those trait docs and rerunning the example. Improve the documentation around the reported byte-count and cursor behavior so a reader can understand why read_f64 returns EOF and how to verify the intended read.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.