diff --git a/Cargo.toml b/Cargo.toml index b73f1a6..8d6fe1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,11 +9,11 @@ authors = ["Yoshua Wuyts "] 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" diff --git a/README.md b/README.md index 424e5c8..4a6225b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/lib.rs b/src/lib.rs index c2cb895..f3172eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;