Skip to content

Commit 376ed95

Browse files
committed
Try to clarify lazy-loading file pointer example
Closes jam1garner#311.
1 parent 5d478b5 commit 376ed95

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

binrw/src/file_ptr.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
//!
8888
//! ## Using a function to lazily load values
8989
//!
90-
//! In this example, only the offset table is parsed. Values pointed to by the
91-
//! offset table are loaded on demand by calling `Object::get` as needed at
92-
//! runtime.
90+
//! In this example, only the offset table is parsed. Items pointed to by the
91+
//! offset table are loaded on demand from the original stream by passing it to
92+
//! `Object::get` along with the index of the desired item.
9393
//!
9494
//! ```
9595
//! # use binrw::{args, BinRead, BinResult, BinReaderExt, helpers::until_eof, io::{Cursor, Read, Seek, SeekFrom}};
@@ -110,7 +110,9 @@
110110
//! }
111111
//!
112112
//! impl Object {
113-
//! pub fn get<R: Read + Seek>(&self, source: &mut R, index: usize) -> Option<BinResult<Item>> {
113+
//! pub fn get<Reader>(&self, source: &mut Reader, index: usize) -> Option<BinResult<Item>>
114+
//! where Reader: Read + Seek
115+
//! {
114116
//! self.offsets.get(index).map(|offset| {
115117
//! let offset = self.data_offset + u64::from(*offset);
116118
//! source.seek(SeekFrom::Start(offset))?;

0 commit comments

Comments
 (0)