Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix example
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
yoshuawuyts committed Nov 10, 2018
1 parent 07fa83d commit e13b20a
Showing 2 changed files with 54 additions and 11 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,18 +10,31 @@ Continuously read,write to disk, using random offsets and lengths. Adapted from

## Usage
```rust
extern crate tempdir;
extern crate random_access_storage;
extern crate random_access_disk;
extern crate tempfile;
extern crate failure;

use std::path::PathBuf;
use tempdir::TempDir;
use random_access_disk::RandomAccessDisk;
use random_access_storage::RandomAccess;
use tempfile::Builder;
use failure::Error;

let dir = TempDir::new("random-access-disk").unwrap();
let mut file = random_access_disk::RandomAccessDisk::new(dir.path().join("README.db"));
fn main () -> Result<(), Error>{
let dir = Builder::new()
.prefix("random-access-disk")
.tempdir()?;

file.write(0, b"hello").unwrap();
file.write(5, b" world").unwrap();
let _text = file.read(0, 11).unwrap();
let file = dir.path().join("example.db");
let mut file = RandomAccessDisk::open(file)?;

file.write(0, b"hello")?;
file.write(5, b" world")?;

let text = file.read(0, 11)?;
assert_eq!(&text, b"hello world");
Ok(())
}
```

## Installation
36 changes: 33 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
#![cfg_attr(feature = "nightly", deny(missing_docs))]
#![cfg_attr(feature = "nightly", feature(external_doc))]
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
#![forbid(unsafe_code, bad_style, future_incompatible)]
#![forbid(rust_2018_idioms, rust_2018_compatibility)]
#![deny(missing_debug_implementations)]
#![forbid(missing_docs)]
#![cfg_attr(test, deny(warnings))]

//! # Example
//! __Basic usage__
//! ```rust
//! # extern crate random_access_storage;
//! # extern crate random_access_disk;
//! # extern crate tempfile;
//! # extern crate failure;
//!
//! use random_access_disk::RandomAccessDisk;
//! use random_access_storage::RandomAccess;
//! use tempfile::Builder;
//! # use failure::Error;
//!
//! # fn main () -> Result<(), Error>{
//! let dir = Builder::new()
//! .prefix("random-access-disk")
//! .tempdir()?;
//!
//! let file = dir.path().join("example.db");
//! let mut file = RandomAccessDisk::open(file)?;
//!
//! file.write(0, b"hello")?;
//! file.write(5, b" world")?;
//!
//! let text = file.read(0, 11)?;
//! assert_eq!(&text, b"hello world");
//! # Ok(())}
//! ```
#[macro_use]
extern crate failure;
extern crate mkdirp;

0 comments on commit e13b20a

Please sign in to comment.