mirror of https://github.com/zkat/cacache-rs.git
docs: add basic examples
This commit is contained in:
parent
180a031b52
commit
4259a39fdf
12
README.md
12
README.md
|
|
@ -4,6 +4,18 @@ A Rust port of [`cacache` for Node.js](https://npm.im/cacache).
|
|||
|
||||
A high-performance, concurrent, content-addressable disk cache.
|
||||
|
||||
## Example
|
||||
|
||||
```rust
|
||||
use cacache;
|
||||
use tempfile;
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let dir = tmp.path().to_owned();
|
||||
cacache::put::data(&dir, "key", b"my-data").unwrap();
|
||||
let data = cacache::get::read(&dir, "key").unwrap();
|
||||
assert_eq!(data, b"my-data");
|
||||
```
|
||||
|
||||
## Install
|
||||
|
||||
Using [`cargo-edit`](https://crates.io/crates/cargo-edit)
|
||||
|
|
|
|||
26
src/lib.rs
26
src/lib.rs
|
|
@ -1,7 +1,31 @@
|
|||
//! cacache is a Rust library for managing local key and content address
|
||||
//! caches. It's really fast, really good at concurrency, and it will never
|
||||
//! give you corrupted data, even if cache files get corrupted or manipulated.
|
||||
|
||||
//!
|
||||
//! ## Examples
|
||||
//! ```
|
||||
//! use cacache;
|
||||
//! # use tempfile;
|
||||
//! # let tmp = tempfile::tempdir().unwrap();
|
||||
//! let dir = tmp.path().to_owned();
|
||||
//! cacache::put::data(&dir, "key", b"my-data").unwrap();
|
||||
//! let data = cacache::get::read(&dir, "key").unwrap();
|
||||
//! assert_eq!(data, b"my-data");
|
||||
//! ```
|
||||
//!
|
||||
//! You can also use the equivalent async APIs using async/await!
|
||||
//! ```
|
||||
//! # use tempfile;
|
||||
//! use cacache;
|
||||
//! # use async_std::task;
|
||||
//! # let tmp = tempfile::tempdir().unwrap();
|
||||
//! let dir = tmp.path().to_owned();
|
||||
//! # task::block_on(async {
|
||||
//! cacache::async_put::data(&dir, "key", b"my-async-data").await.unwrap();
|
||||
//! let data = cacache::async_get::read(&dir, "key").await.unwrap();
|
||||
//! assert_eq!(data, b"my-async-data");
|
||||
//! # })
|
||||
//! ```
|
||||
#![warn(missing_docs, missing_doc_code_examples)]
|
||||
|
||||
pub use serde_json::Value;
|
||||
|
|
|
|||
Loading…
Reference in New Issue