From 086cbfe3794cd47131b6ed3f8175668ae6a9eb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 18 Oct 2019 21:49:47 -0400 Subject: [PATCH] docs: add a couple of examples to Put --- src/put.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/put.rs b/src/put.rs index 78a2bca..da09628 100644 --- a/src/put.rs +++ b/src/put.rs @@ -17,6 +17,23 @@ use crate::index; use std::task::{Context, Poll}; /// Writes `data` to the `cache`, indexing it under `key`. +/// +/// ## Example +/// ```no_run +/// # use async_std::prelude::*; +/// # use async_std::task; +/// # fn main() -> Result<(), cacache::Error> { +/// # task::block_on(async { +/// # example().await.unwrap(); +/// # }); +/// # Ok(()) +/// # } +/// # +/// # async fn example() -> Result<(), cacache::Error> { +/// cacache::put::data("./my-cache", "my-key", b"hello").await?; +/// # Ok(()) +/// # } +/// ``` pub async fn data(cache: P, key: K, data: D) -> Result where P: AsRef, @@ -89,6 +106,15 @@ impl AsyncPut { } /// Writes `data` to the `cache` synchronously, indexing it under `key`. +/// +/// ## Example +/// ```no_run +/// # fn main() -> Result<(), cacache::Error> { +/// # use std::io::Read; +/// let data = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; +/// # Ok(()) +/// # } +/// ``` pub fn data_sync(cache: P, key: K, data: D) -> Result where P: AsRef, @@ -123,7 +149,7 @@ impl PutOpts { Default::default() } - /// Opens the file handle for writing, returning a Put instance. + /// Opens the file handle for writing, returning an AsyncPut instance. pub async fn open(self, cache: P, key: K) -> Result where P: AsRef, @@ -142,7 +168,7 @@ impl PutOpts { }) } - /// Opens the file handle for writing synchronously, returning a Put instance. + /// Opens the file handle for writing synchronously, returning a SyncPut instance. pub fn open_sync(self, cache: P, key: K) -> Result where P: AsRef,