From ce50afa63548251d86a5384ab02ae433a1f8c8cb Mon Sep 17 00:00:00 2001 From: Radical Date: Wed, 25 Jun 2025 14:08:15 +0200 Subject: [PATCH 1/3] docs: update docs to reflect current code --- src/bunny/mod.rs | 20 ++++++++++---------- src/edge_storage/mod.rs | 40 ++++++++++++++++------------------------ src/lib.rs | 4 ++-- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/bunny/mod.rs b/src/bunny/mod.rs index 231e02a..3a373bc 100644 --- a/src/bunny/mod.rs +++ b/src/bunny/mod.rs @@ -1,4 +1,4 @@ -//! Contains structs, enums and implementations for the main bunny.net API +//! Contains structs, enums and implementations for the main Bunny.net API use url::Url; @@ -24,7 +24,7 @@ pub struct BunnyClient { } impl BunnyClient { - /// Creates a new BunnyClient using the supplied `api_key` + /// Creates a new Bunny.net API Client using the supplied `api_key` /// /// ``` /// use bunny_api_tokio::{BunnyClient, error::Error}; @@ -54,12 +54,12 @@ impl BunnyClient { /// Returns a list of countries and tax rates /// /// ``` - /// use bunny_api_tokio::{Client, error::Error}; + /// use bunny_api_tokio::{BunnyClient, error::Error}; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { /// // Bunny.net api key - /// let mut client = Client::new("api_key").await?; + /// let mut client = BunnyClient::new("api_key").await?; /// /// let countries = client.get_country_list().await?; /// @@ -87,12 +87,12 @@ impl BunnyClient { /// Returns a list of API Keys /// /// ``` - /// use bunny_api_tokio::{Client, error::Error}; + /// use bunny_api_tokio::{BunnyClient, error::Error}; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { /// // Bunny.net api key - /// let mut client = Client::new("api_key").await?; + /// let mut client = BunnyClient::new("api_key").await?; /// /// let api_keys = client.list_api_keys(1, 1000).await?; /// @@ -124,12 +124,12 @@ impl BunnyClient { /// Returns a list of Regions /// /// ``` - /// use bunny_api_tokio::{Client, error::Error}; + /// use bunny_api_tokio::{BunnyClient, error::Error}; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { /// // Bunny.net api key - /// let mut client = Client::new("api_key").await?; + /// let mut client = BunnyClient::new("api_key").await?; /// /// let regions = client.region_list().await?; /// @@ -156,12 +156,12 @@ impl BunnyClient { /// Purges a URL from the cache /// /// ``` - /// use bunny_api_tokio::{Client, error::Error}; + /// use bunny_api_tokio::{BunnyClient, error::Error}; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { /// // Bunny.net api key - /// let mut client = Client::new("api_key").await?; + /// let mut client = BunnyClient::new("api_key").await?; /// /// client.purge_url("https://url_to_purge.com".parse()?, false).await?; /// diff --git a/src/edge_storage/mod.rs b/src/edge_storage/mod.rs index 69e9131..adcd2c4 100644 --- a/src/edge_storage/mod.rs +++ b/src/edge_storage/mod.rs @@ -20,7 +20,7 @@ pub struct EdgeStorageClient { } impl<'a> EdgeStorageClient { - /// Creates a new EdgeStorageClient using the supplied `api_key` + /// Creates a new EdgeStorageClient /// /// ``` /// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint}; @@ -53,19 +53,17 @@ impl<'a> EdgeStorageClient { /// Uploads a file to the Storage Zone /// /// ``` - /// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint}; + /// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint}; /// use tokio::fs; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { - /// let mut client = Client::new("api_key").await?; - /// - /// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; + /// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; /// /// let file_bytes = fs::read("path/to/file.png").await.unwrap(); /// /// // Will put a file in STORAGE_ZONE/images/file.png - /// client.storage.upload("/images/file.png", file_bytes.into()).await?; + /// client.upload("/images/file.png", file_bytes.into()).await?; /// /// Ok(()) /// } @@ -91,18 +89,16 @@ impl<'a> EdgeStorageClient { /// Downloads a file from the Storage Zone /// /// ``` - /// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint}; + /// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint}; /// use tokio::fs; /// use tokio::io::AsyncWriteExt; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { - /// let mut client = Client::new("api_key").await?; - /// - /// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; - /// + /// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; + /// /// // Will download the file STORAGE_ZONE/images/file.png - /// let contents = client.storage.download("/images/file.png").await?; + /// let contents = client.download("/images/file.png").await?; /// /// let mut file = fs::File::create("file.png").await.unwrap(); /// file.write_all(&contents).await.unwrap(); @@ -130,16 +126,14 @@ impl<'a> EdgeStorageClient { /// Deletes a file from the Storage Zone /// /// ``` - /// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint}; + /// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint}; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { - /// let mut client = Client::new("api_key").await?; - /// - /// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; - /// + /// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; + /// /// // Will delete the file STORAGE_ZONE/images/file.png - /// client.storage.delete("/images/file.png").await?; + /// client.delete("/images/file.png").await?; /// /// Ok(()) /// } @@ -163,16 +157,14 @@ impl<'a> EdgeStorageClient { /// Lists files on the Storage Zone /// /// ``` - /// use bunny_api_tokio::{Client, error::Error, edge_storage::Endpoint}; + /// use bunny_api_tokio::{EdgeStorageClient, error::Error, edge_storage::Endpoint}; /// /// #[tokio::main] /// async fn main() -> Result<(), Error> { - /// let mut client = Client::new("api_key").await?; - /// - /// client.storage.init("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; - /// + /// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; + /// /// // Will list the files in STORAGE_ZONE/images/ - /// let files = client.storage.list("/images/").await?; + /// let files = client.list("/images/").await?; /// /// println!("{:#?}", files); /// diff --git a/src/lib.rs b/src/lib.rs index 6998c3a..f20de92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,11 @@ //! 2. Start coding //! //! ``` -//! use bunny_api_tokio::{Client, error::Error}; +//! use bunny_api_tokio::{BunnyClient, error::Error}; //! //! #[tokio::main] //! async fn main() -> Result<(), Error> { -//! let mut client = Client::new("api_key").await?; +//! let mut client = BunnyClient::new("api_key").await?; //! //! Ok(()) //! } From 8412489373649f30359b045e98d4ef7fd39c8060 Mon Sep 17 00:00:00 2001 From: Radical Date: Wed, 25 Jun 2025 14:08:27 +0200 Subject: [PATCH 2/3] make docs.rs build with all features --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 435b3c6..897928d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,3 +34,6 @@ serde = { version = "1.0.219", features = ["derive"] } thiserror = "2.0.12" tokio = "1.45.1" url = { version = "2.5.4", features = ["serde"] } + +[package.metadata.docs.rs] +all-features = true From 57e76753f562ac408fb8d890bfd54121a1dc5e1c Mon Sep 17 00:00:00 2001 From: Radical Date: Wed, 25 Jun 2025 14:09:18 +0200 Subject: [PATCH 3/3] style: cargo fmt --- src/bunny/mod.rs | 4 +--- src/edge_storage/endpoint.rs | 2 +- src/edge_storage/mod.rs | 24 ++++++++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/bunny/mod.rs b/src/bunny/mod.rs index 3a373bc..7146d57 100644 --- a/src/bunny/mod.rs +++ b/src/bunny/mod.rs @@ -44,9 +44,7 @@ impl BunnyClient { let reqwest = RClient::builder().default_headers(headers).build()?; - Ok(Self { - reqwest, - }) + Ok(Self { reqwest }) } // TODO: Following functions could probably use better naming, the names are currently derived from the titles on the API reference diff --git a/src/edge_storage/endpoint.rs b/src/edge_storage/endpoint.rs index 555c0cc..42b522b 100644 --- a/src/edge_storage/endpoint.rs +++ b/src/edge_storage/endpoint.rs @@ -1,5 +1,5 @@ -use url::Url; use crate::error::Error; +use url::Url; /// Endpoints for Edge Storage API #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/src/edge_storage/mod.rs b/src/edge_storage/mod.rs index adcd2c4..c3147ba 100644 --- a/src/edge_storage/mod.rs +++ b/src/edge_storage/mod.rs @@ -1,10 +1,13 @@ //! Edge Storage API -//! +//! //! Contains enums, structs and functions for the Bunny Edge Storage API use crate::error::Error; use bytes::Bytes; -use reqwest::{header::{HeaderMap, HeaderValue}, Client}; +use reqwest::{ + Client, + header::{HeaderMap, HeaderValue}, +}; use url::Url; mod endpoint; @@ -32,7 +35,11 @@ impl<'a> EdgeStorageClient { /// Ok(()) /// } /// ``` - pub async fn new, T1: AsRef>(api_key: T, endpoint: Endpoint, storage_zone: T1) -> Result { + pub async fn new, T1: AsRef>( + api_key: T, + endpoint: Endpoint, + storage_zone: T1, + ) -> Result { let mut headers = HeaderMap::new(); headers.append("AccessKey", HeaderValue::from_str(api_key.as_ref())?); headers.append("accept", HeaderValue::from_str("application/json")?); @@ -44,10 +51,7 @@ impl<'a> EdgeStorageClient { let url = endpoint.join(&storage_zone)?; - Ok(Self { - url, - reqwest, - }) + Ok(Self { url, reqwest }) } /// Uploads a file to the Storage Zone @@ -96,7 +100,7 @@ impl<'a> EdgeStorageClient { /// #[tokio::main] /// async fn main() -> Result<(), Error> { /// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; - /// + /// /// // Will download the file STORAGE_ZONE/images/file.png /// let contents = client.download("/images/file.png").await?; /// @@ -131,7 +135,7 @@ impl<'a> EdgeStorageClient { /// #[tokio::main] /// async fn main() -> Result<(), Error> { /// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; - /// + /// /// // Will delete the file STORAGE_ZONE/images/file.png /// client.delete("/images/file.png").await?; /// @@ -162,7 +166,7 @@ impl<'a> EdgeStorageClient { /// #[tokio::main] /// async fn main() -> Result<(), Error> { /// let mut client = EdgeStorageClient::new("storage_zone_api_key", Endpoint::Frankfurt, "MyStorageZone").await?; - /// + /// /// // Will list the files in STORAGE_ZONE/images/ /// let files = client.list("/images/").await?; ///