Skip to content

Commit 3af2222

Browse files
committed
fix example
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
1 parent 07fa83d commit 3af2222

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

README.md

+21-8
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@ Continuously read,write to disk, using random offsets and lengths. Adapted from
1010

1111
## Usage
1212
```rust
13-
extern crate tempdir;
13+
extern crate random_access_storage;
1414
extern crate random_access_disk;
15+
extern crate tempfile;
16+
extern crate failure;
1517

16-
use std::path::PathBuf;
17-
use tempdir::TempDir;
18+
use random_access_disk::RandomAccessDisk;
19+
use random_access_storage::RandomAccess;
20+
use tempfile::Builder;
21+
use failure::Error;
1822

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

22-
file.write(0, b"hello").unwrap();
23-
file.write(5, b" world").unwrap();
24-
let _text = file.read(0, 11).unwrap();
28+
let file = dir.path().join("example.db");
29+
let mut file = RandomAccessDisk::open(file)?;
30+
31+
file.write(0, b"hello")?;
32+
file.write(5, b" world")?;
33+
34+
let text = file.read(0, 11)?;
35+
assert_eq!(&text, b"hello world");
36+
Ok(())
37+
}
2538
```
2639

2740
## Installation

src/lib.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
1-
#![cfg_attr(feature = "nightly", deny(missing_docs))]
2-
#![cfg_attr(feature = "nightly", feature(external_doc))]
3-
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
1+
#![forbid(unsafe_code, bad_style, future_incompatible)]
2+
#![forbid(rust_2018_idioms, rust_2018_compatibility)]
3+
#![deny(missing_debug_implementations)]
4+
#![forbid(missing_docs)]
45
#![cfg_attr(test, deny(warnings))]
56

7+
//! # Example
8+
//! __Basic usage__
9+
//! ```rust
10+
//! # extern crate random_access_storage;
11+
//! # extern crate random_access_disk;
12+
//! # extern crate tempfile;
13+
//! # extern crate failure;
14+
//! use random_access_disk::RandomAccessDisk;
15+
//! use random_access_storage::RandomAccess;
16+
//! use tempfile::Builder;
17+
//! # use failure::Error;
18+
//!
19+
//! # fn main () -> Result<(), Error>{
20+
//! let dir = Builder::new()
21+
//! .prefix("random-access-disk")
22+
//! .tempdir()?;
23+
//!
24+
//! let file = dir.path().join("example.db");
25+
//! let mut file = RandomAccessDisk::open(file)?;
26+
//!
27+
//! file.write(0, b"hello")?;
28+
//! file.write(5, b" world")?;
29+
//!
30+
//! let text = file.read(0, 11)?;
31+
//! assert_eq!(&text, b"hello world");
32+
//! # Ok(())}
33+
//! ```
34+
635
#[macro_use]
736
extern crate failure;
837
extern crate mkdirp;

0 commit comments

Comments
 (0)