diff --git a/src/get.rs b/src/get.rs index 21c0599..21419b4 100644 --- a/src/get.rs +++ b/src/get.rs @@ -41,24 +41,19 @@ impl AsyncGet { /// /// ## Example /// ```no_run - /// # use async_std::prelude::*; - /// # use async_std::task; - /// # use anyhow::Result; - /// # fn main() -> Result<()> { - /// # task::block_on(async { - /// # example().await.unwrap(); - /// # }); - /// # Ok(()) - /// # } - /// # - /// # async fn example() -> Result<()> { - /// let mut handle = cacache::get::open("./my-cache", "my-key").await?; - /// let mut str = String::new(); - /// handle.read_to_string(&mut str).await?; - /// // Remember to check that the data you got was correct! - /// handle.check()?; - /// # Ok(()) - /// # } + /// use async_std::prelude::*; + /// use async_attributes; + /// use anyhow::Result; + /// + /// #[async_attributes::main] + /// async fn main() -> Result<()> { + /// let mut handle = cacache::get::open("./my-cache", "my-key").await?; + /// let mut str = String::new(); + /// handle.read_to_string(&mut str).await?; + /// // Remember to check that the data you got was correct! + /// handle.check()?; + /// Ok(()) + /// } /// ``` pub fn check(self) -> Result { self.reader @@ -72,24 +67,19 @@ impl AsyncGet { /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let mut handle = cacache::get::open("./my-cache", "my-key").await?; -/// let mut str = String::new(); -/// handle.read_to_string(&mut str).await?; -/// // Remember to check that the data you got was correct! -/// handle.check()?; -/// # Ok(()) -/// # } +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; +/// +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let mut handle = cacache::get::open("./my-cache", "my-key").await?; +/// let mut str = String::new(); +/// handle.read_to_string(&mut str).await?; +/// // Remember to check that the data you got was correct! +/// handle.check()?; +/// Ok(()) +/// } /// ``` pub async fn open(cache: P, key: K) -> Result where @@ -110,25 +100,20 @@ where /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let sri = cacache::put::data("./my-cache", "key", b"hello world").await?; -/// let mut handle = cacache::get::open_hash("./my-cache", sri).await?; -/// let mut str = String::new(); -/// handle.read_to_string(&mut str).await?; -/// // Remember to check that the data you got was correct! -/// handle.check()?; -/// # Ok(()) -/// # } +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; +/// +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let sri = cacache::put::data("./my-cache", "key", b"hello world").await?; +/// let mut handle = cacache::get::open_hash("./my-cache", sri).await?; +/// let mut str = String::new(); +/// handle.read_to_string(&mut str).await?; +/// // Remember to check that the data you got was correct! +/// handle.check()?; +/// Ok(()) +/// } /// ``` pub async fn open_hash

(cache: P, sri: Integrity) -> Result where @@ -144,20 +129,15 @@ where /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let data = cacache::get::data("./my-cache", "my-key").await?; -/// # Ok(()) -/// # } +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; +/// +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let data = cacache::get::data("./my-cache", "my-key").await?; +/// Ok(()) +/// } /// ``` pub async fn data(cache: P, key: K) -> Result> where @@ -179,21 +159,16 @@ where /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; -/// let data = cacache::get::data_hash("./my-cache", &sri).await?; -/// # Ok(()) -/// # } +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; +/// +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; +/// let data = cacache::get::data_hash("./my-cache", &sri).await?; +/// Ok(()) +/// } /// ``` pub async fn data_hash

(cache: P, sri: &Integrity) -> Result> where @@ -206,20 +181,15 @@ where /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// cacache::get::copy("./my-cache", "my-key", "./data.txt").await?; -/// # Ok(()) -/// # } +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; +/// +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// cacache::get::copy("./my-cache", "my-key", "./data.txt").await?; +/// Ok(()) +/// } /// ``` pub async fn copy(cache: P, key: K, to: Q) -> Result where @@ -241,21 +211,16 @@ where /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let sri = cacache::put::data("./my-cache", "my-key", b"hello world").await?; -/// cacache::get::copy_hash("./my-cache", &sri, "./data.txt").await?; -/// # Ok(()) -/// # } +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; +/// +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let sri = cacache::put::data("./my-cache", "my-key", b"hello world").await?; +/// cacache::get::copy_hash("./my-cache", &sri, "./data.txt").await?; +/// Ok(()) +/// } /// ``` pub async fn copy_hash(cache: P, sri: &Integrity, to: Q) -> Result where @@ -307,16 +272,17 @@ impl SyncGet { /// /// ## Example /// ```no_run - /// # use anyhow::Result; - /// # fn main() -> Result<()> { - /// # use std::io::Read; - /// let mut handle = cacache::get::open_sync("./my-cache", "my-key")?; - /// let mut str = String::new(); + /// use anyhow::Result; + /// use std::io::Read; + /// + /// fn main() -> Result<()> { + /// let mut handle = cacache::get::open_sync("./my-cache", "my-key")?; + /// let mut str = String::new(); /// handle.read_to_string(&mut str)?; - /// // Remember to check that the data you got was correct! - /// handle.check()?; - /// # Ok(()) - /// # } + /// // Remember to check that the data you got was correct! + /// handle.check()?; + /// Ok(()) + /// } /// ``` pub fn check(self) -> Result { self.reader @@ -330,16 +296,17 @@ impl SyncGet { /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let mut handle = cacache::get::open_sync("./my-cache", "my-key")?; -/// let mut str = String::new(); -/// handle.read_to_string(&mut str)?; -/// // Remember to check that the data you got was correct! -/// handle.check()?; -/// # Ok(()) -/// # } +/// use anyhow::Result; +/// use std::io::Read; +/// +/// fn main() -> Result<()> { +/// let mut handle = cacache::get::open_sync("./my-cache", "my-key")?; +/// let mut str = String::new(); +/// handle.read_to_string(&mut str)?; +/// // Remember to check that the data you got was correct! +/// handle.check()?; +/// Ok(()) +/// } /// ``` pub fn open_sync(cache: P, key: K) -> Result where @@ -360,17 +327,18 @@ where /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let sri = cacache::put::data_sync("./my-cache", "key", b"hello world")?; -/// let mut handle = cacache::get::open_hash_sync("./my-cache", sri)?; -/// let mut str = String::new(); -/// handle.read_to_string(&mut str)?; -/// // Remember to check that the data you got was correct! -/// handle.check()?; -/// # Ok(()) -/// # } +/// use anyhow::Result; +/// use std::io::Read; +/// +/// fn main() -> Result<()> { +/// let sri = cacache::put::data_sync("./my-cache", "key", b"hello world")?; +/// let mut handle = cacache::get::open_hash_sync("./my-cache", sri)?; +/// let mut str = String::new(); +/// handle.read_to_string(&mut str)?; +/// // Remember to check that the data you got was correct! +/// handle.check()?; +/// Ok(()) +/// } /// ``` pub fn open_hash_sync

(cache: P, sri: Integrity) -> Result where @@ -386,12 +354,13 @@ where /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let data = cacache::get::data_sync("./my-cache", "my-key")?; -/// # Ok(()) -/// # } +/// use anyhow::Result; +/// use std::io::Read; +/// +/// fn main() -> Result<()> { +/// let data = cacache::get::data_sync("./my-cache", "my-key")?; +/// Ok(()) +/// } /// ``` pub fn data_sync(cache: P, key: K) -> Result> where @@ -413,13 +382,14 @@ where /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; -/// let data = cacache::get::data_hash_sync("./my-cache", &sri)?; -/// # Ok(()) -/// # } +/// use anyhow::Result; +/// use std::io::Read; +/// +/// fn main() -> Result<()> { +/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; +/// let data = cacache::get::data_hash_sync("./my-cache", &sri)?; +/// Ok(()) +/// } /// ``` pub fn data_hash_sync

(cache: P, sri: &Integrity) -> Result> where @@ -432,12 +402,13 @@ where /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// cacache::get::copy_sync("./my-cache", "my-key", "./my-hello.txt")?; -/// # Ok(()) -/// # } +/// use anyhow::Result; +/// use std::io::Read; +/// +/// fn main() -> Result<()> { +/// cacache::get::copy_sync("./my-cache", "my-key", "./my-hello.txt")?; +/// Ok(()) +/// } /// ``` pub fn copy_sync(cache: P, key: K, to: Q) -> Result where @@ -459,13 +430,14 @@ where /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; -/// cacache::get::copy_hash_sync("./my-cache", &sri, "./my-hello.txt")?; -/// # Ok(()) -/// # } +/// use anyhow::Result; +/// use std::io::Read; +/// +/// fn main() -> Result<()> { +/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; +/// cacache::get::copy_hash_sync("./my-cache", &sri, "./my-hello.txt")?; +/// Ok(()) +/// } /// ``` pub fn copy_hash_sync(cache: P, sri: &Integrity, to: Q) -> Result where diff --git a/src/put.rs b/src/put.rs index 0712489..fa5cd9b 100644 --- a/src/put.rs +++ b/src/put.rs @@ -21,20 +21,14 @@ use std::task::{Context as TaskContext, Poll}; /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// cacache::put::data("./my-cache", "my-key", b"hello").await?; -/// # Ok(()) -/// # } +/// use async_attributes; +/// use anyhow::Result; +/// +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// cacache::put::data("./my-cache", "my-key", b"hello").await?; +/// Ok(()) +/// } /// ``` pub async fn data(cache: P, key: K, data: D) -> Result where @@ -144,12 +138,13 @@ impl AsyncPut { /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let data = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; -/// # Ok(()) -/// # } +/// use anyhow::Result; +/// use std::io::Read; +/// +/// fn main() -> Result<()> { +/// 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 diff --git a/src/rm.rs b/src/rm.rs index 899c2c4..b9b2c00 100644 --- a/src/rm.rs +++ b/src/rm.rs @@ -15,28 +15,23 @@ use crate::index; /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; /// -/// cacache::rm::entry("./my-cache", "my-key").await?; +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; /// -/// // This fails: -/// cacache::get::data("./my-cache", "my-key").await?; +/// cacache::rm::entry("./my-cache", "my-key").await?; /// -/// // But this succeeds: -/// cacache::get::data_hash("./my-cache", &sri).await?; -/// # Ok(()) -/// # } +/// // This fails: +/// cacache::get::data("./my-cache", "my-key").await?; +/// +/// // But this succeeds: +/// cacache::get::data_hash("./my-cache", &sri).await?; +/// Ok(()) +/// } /// ``` pub async fn entry(cache: P, key: K) -> Result<()> where @@ -59,29 +54,25 @@ where /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; /// -/// cacache::rm::entry("./my-cache", "my-key").await?; +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; /// -/// // These fail: -/// cacache::get::data("./my-cache", "my-key").await?; -/// cacache::get::data_hash("./my-cache", &sri).await?; +/// cacache::rm::entry("./my-cache", "my-key").await?; /// -/// // But this succeeds: -/// cacache::get::entry("./my-cache", "my-key").await?; -/// # Ok(()) -/// # } +/// // These fail: +/// cacache::get::data("./my-cache", "my-key").await?; +/// cacache::get::data_hash("./my-cache", &sri).await?; +/// +/// // But this succeeds: +/// cacache::get::entry("./my-cache", "my-key").await?; +/// +/// Ok(()) +/// } /// ``` pub async fn content>(cache: P, sri: &Integrity) -> Result<()> { rm::rm_async(cache.as_ref(), &sri).await.with_context(|| { @@ -98,27 +89,23 @@ pub async fn content>(cache: P, sri: &Integrity) -> Result<()> { /// /// ## Example /// ```no_run -/// # use async_std::prelude::*; -/// # use async_std::task; -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # task::block_on(async { -/// # example().await.unwrap(); -/// # }); -/// # Ok(()) -/// # } -/// # -/// # async fn example() -> Result<()> { -/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; +/// use async_std::prelude::*; +/// use async_attributes; +/// use anyhow::Result; /// -/// cacache::rm::entry("./my-cache", "my-key").await?; +/// #[async_attributes::main] +/// async fn main() -> Result<()> { +/// let sri = cacache::put::data("./my-cache", "my-key", b"hello").await?; /// -/// // These all fail: -/// cacache::get::data("./my-cache", "my-key").await?; -/// cacache::get::entry("./my-cache", "my-key").await?; -/// cacache::get::data_hash("./my-cache", &sri).await?; -/// # Ok(()) -/// # } +/// cacache::rm::entry("./my-cache", "my-key").await?; +/// +/// // These all fail: +/// cacache::get::data("./my-cache", "my-key").await?; +/// cacache::get::entry("./my-cache", "my-key").await?; +/// cacache::get::data_hash("./my-cache", &sri).await?; +/// +/// Ok(()) +/// } /// ``` pub async fn all>(cache: P) -> Result<()> { for entry in cache.as_ref().read_dir()? { @@ -134,20 +121,22 @@ pub async fn all>(cache: P) -> Result<()> { /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; +/// use anyhow::Result; +/// use std::io::Read; /// -/// cacache::rm::entry_sync("./my-cache", "my-key")?; +/// fn main() -> Result<()> { +/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; /// -/// // This fails: -/// cacache::get::data_sync("./my-cache", "my-key")?; +/// cacache::rm::entry_sync("./my-cache", "my-key")?; /// -/// // But this succeeds: -/// cacache::get::data_hash_sync("./my-cache", &sri)?; -/// # Ok(()) -/// # } +/// // This fails: +/// cacache::get::data_sync("./my-cache", "my-key")?; +/// +/// // But this succeeds: +/// cacache::get::data_hash_sync("./my-cache", &sri)?; +/// +/// Ok(()) +/// } /// ``` pub fn entry_sync(cache: P, key: K) -> Result<()> where @@ -168,21 +157,23 @@ where /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; +/// use anyhow::Result; +/// use std::io::Read; /// -/// cacache::rm::entry_sync("./my-cache", "my-key")?; +/// fn main() -> Result<()> { +/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; /// -/// // These fail: -/// cacache::get::data_sync("./my-cache", "my-key")?; -/// cacache::get::data_hash_sync("./my-cache", &sri)?; +/// cacache::rm::entry_sync("./my-cache", "my-key")?; /// -/// // But this succeeds: -/// cacache::get::entry_sync("./my-cache", "my-key")?; -/// # Ok(()) -/// # } +/// // These fail: +/// cacache::get::data_sync("./my-cache", "my-key")?; +/// cacache::get::data_hash_sync("./my-cache", &sri)?; +/// +/// // But this succeeds: +/// cacache::get::entry_sync("./my-cache", "my-key")?; +/// +/// Ok(()) +/// } /// ``` pub fn content_sync>(cache: P, sri: &Integrity) -> Result<()> { rm::rm(cache.as_ref(), &sri).with_context(|| { @@ -199,19 +190,21 @@ pub fn content_sync>(cache: P, sri: &Integrity) -> Result<()> { /// /// ## Example /// ```no_run -/// # use anyhow::Result; -/// # fn main() -> Result<()> { -/// # use std::io::Read; -/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; +/// use anyhow::Result; +/// use std::io::Read; /// -/// cacache::rm::entry_sync("./my-cache", "my-key")?; +/// fn main() -> Result<()> { +/// let sri = cacache::put::data_sync("./my-cache", "my-key", b"hello")?; /// -/// // These all fail: -/// cacache::get::data_sync("./my-cache", "my-key")?; -/// cacache::get::data_hash_sync("./my-cache", &sri)?; -/// cacache::get::entry_sync("./my-cache", "my-key")?; -/// # Ok(()) -/// # } +/// cacache::rm::entry_sync("./my-cache", "my-key")?; +/// +/// // These all fail: +/// cacache::get::data_sync("./my-cache", "my-key")?; +/// cacache::get::data_hash_sync("./my-cache", &sri)?; +/// cacache::get::entry_sync("./my-cache", "my-key")?; +/// +/// Ok(()) +/// } /// ``` pub fn all_sync>(cache: P) -> Result<()> { for entry in cache.as_ref().read_dir()? {