#buffer #io #reader #seek #bufread #replace

seek_bufread

具有定位支持的 std::io::BufReader 的直接替换品

5 个稳定版本

使用旧的 Rust 2015

1.2.2 2018年12月6日
1.2.0 2016年10月22日
1.1.1 2016年10月22日
1.0.2 2016年10月21日

#2 in #seek

Download history 94/week @ 2024-03-13 114/week @ 2024-03-20 122/week @ 2024-03-27 114/week @ 2024-04-03 96/week @ 2024-04-10 90/week @ 2024-04-17 87/week @ 2024-04-24 91/week @ 2024-05-01 100/week @ 2024-05-08 100/week @ 2024-05-15 94/week @ 2024-05-22 97/week @ 2024-05-29 75/week @ 2024-06-05 64/week @ 2024-06-12 78/week @ 2024-06-19 77/week @ 2024-06-26

306 每月下载量
10 软件包中使用(8 个直接使用)

Apache-2.0

21KB
323

seek_bufread

Build Status Coverage Status Crates.io

具有定位支持的 std::io::BufReader 的直接替换品。

完整文档

快速示例

use std::io::{self, Cursor, Read, Seek, SeekFrom};
use seek_bufread::BufReader;

let inner = Cursor::new([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
let mut reader = BufReader::new(inner);

reader.seek(SeekFrom::Current(4)).unwrap();
let mut buf = [0; 8];

// read bytes from internal buffer
reader.read(&mut buf).unwrap();
assert_eq!(buf, [4, 5, 6, 7, 8, 9, 10, 11]);

使用方法

将此内容放入你的 Cargo.toml

[dependencies]
seek_bufread = "~1.2"

并将此内容放入你的软件包根目录

extern crate seek_bufread;

基准测试

_std 为后缀的测试使用标准的 std::io::BufRead 实现。在不进行定位操作的情况下,两者整体性能相当相似。在进行定位操作时,seek_bufread::BufRead 明显更快。

test tests::read_10mb_default_from_cursor        ... bench:   6,044,915 ns/iter (+/- 275,518)
test tests::read_10mb_default_from_cursor_std    ... bench:   6,038,466 ns/iter (+/- 227,145)
test tests::read_10mb_default_from_file          ... bench:   4,213,179 ns/iter (+/- 116,043)
test tests::read_10mb_default_from_file_std      ... bench:   4,224,658 ns/iter (+/- 132,629)
test tests::read_10mb_fullbuf_from_file          ... bench:   7,280,470 ns/iter (+/- 209,827)
test tests::read_10mb_fullbuf_from_file_std      ... bench:   7,448,666 ns/iter (+/- 2,720,199)
test tests::read_10mb_halfbuf_from_file          ... bench:   5,962,017 ns/iter (+/- 415,952)
test tests::read_10mb_halfbuf_from_file_std      ... bench:   5,904,902 ns/iter (+/- 240,471)
test tests::read_seek_10mb_default_from_file     ... bench:       6,621 ns/iter (+/- 145)
test tests::read_seek_10mb_default_from_file_std ... bench:      59,651 ns/iter (+/- 1,993)
test tests::read_seek_10mb_halfbuf_from_file     ... bench:   1,168,511 ns/iter (+/- 63,956)
test tests::read_seek_10mb_halfbuf_from_file_std ... bench:  62,872,335 ns/iter (+/- 5,344,766)

许可证

Apache-2.0

无运行时依赖