Skip to content

Commit

Permalink
remove Buffer's Read implementation
Browse files Browse the repository at this point in the history
The previous implementation was incorrect because it essentially
recreated a slice of the Buffer on each call, meaning that read progress
information was lost across calls.

The implementation has been removed since the implementation was very
basic anyways.

Going forward, one can Read from a Buffer by first getting a slice of
the Buffer and then using _its_ Read implementation. See the regression
test in this commit for an example of using read_to_end().

Fixes #6
  • Loading branch information
blaenk committed Nov 8, 2016
1 parent ac64860 commit 6d94343
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hoedown"
version = "5.0.0"
version = "6.0.0"
authors = ["Jorge Israel Peña <[email protected]>"]
description = "bindings for the Hoedown markdown processor"
repository = "https://github.com/blaenk/hoedown"
Expand All @@ -14,6 +14,7 @@ libc = "0.2"

[dev-dependencies]
glob = "0.2"
timebomb = "0.1.2"

[build-dependencies]
gcc = "0.3"
7 changes: 0 additions & 7 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ impl Clone for Buffer {
}
}

impl Read for Buffer {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut buffer: &[u8] = self.as_ref();
Read::read(&mut buffer, buf)
}
}

impl Write for Buffer {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
unsafe {
Expand Down
21 changes: 21 additions & 0 deletions tests/buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extern crate hoedown;
extern crate timebomb;

use std::vec::Vec;
use std::io::Read;

use hoedown::Buffer;

use timebomb::timeout_ms;

#[test]
fn test_read_to_end() {
let buffer = Buffer::from("This is a test");
let mut destination = Vec::new();

timeout_ms(move || {
let mut slice: &[u8] = &buffer;

slice.read_to_end(&mut destination).unwrap();
}, 1000);
}

0 comments on commit 6d94343

Please sign in to comment.