Skip to content

Commit

Permalink
Add rustdoc example for reader()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrSensor committed Jan 10, 2024
1 parent 6d02ac8 commit 319b6c3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ impl RandomAccessDisk {
}

/// Acquire buffered reader.
/// # Examples
/// Read each lines to delete on specific line/column
///
/// ```no_run
/// # use random_access_disk::RandomAccessDisk;
/// # use random_access_storage::RandomAccess;
/// # use async_std::prelude::*;
/// # #[async_std::main]
/// # async fn main() {
/// let line = 10;
/// let column = 10;
/// let length = 5;
///
/// let mut file = RandomAccessDisk::open("text.db").await.unwrap();
///
/// let offset = column + file.reader()
/// .lines().take(line - 1)
/// .fold(column, |acc, line| acc + line.unwrap().len() as u64)
/// .await;
///
/// let _ = file.del(offset, length).await;
/// # }
/// ```
pub fn reader(&self) -> BufReader<&fs::File> {
BufReader::new(&self.file)
}
Expand Down

0 comments on commit 319b6c3

Please sign in to comment.