Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix example #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ authors = ["Yoshua Wuyts <[email protected]>"]
readme = "README.md"

[dependencies]
failure = "0.1.1"
failure = "0.1.3"
random-access-storage = "0.6.0"
mkdirp = "0.1.0"

[dev-dependencies]
quickcheck = "0.7.1"
tempfile = "3.0.3"
quickcheck = "0.7.2"
tempfile = "3.0.4"
rand = "0.5.5"
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 32 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +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))]
#![feature(tool_lints)]

//! # 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;
Expand Down