Skip to content

Commit a12d170

Browse files
committed
tweak(cache): re-export CacheBuilder::new
docs have also been updated to use this new method in the examples, as it's more intuitive to use this instead of CacheBuilder::new
1 parent e390951 commit a12d170

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ impl CacheBuilder {
9090
/// ```rust
9191
/// # #[tokio::main(flavor = "current_thread")]
9292
/// # async fn main() {
93-
/// use forceps::CacheBuilder;
93+
/// use forceps::Cache;
9494
///
95-
/// let cache = CacheBuilder::new("./cache")
95+
/// let cache = Cache::new("./cache")
9696
/// .build()
9797
/// .await
9898
/// .unwrap();

src/cache.rs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ pub(crate) struct Options {
3232
/// The main component of `forceps`, acts as the API for interacting with the on-disk API.
3333
///
3434
/// This structure exposes `read`, `write`, and misc metadata operations. `read` and `write` are
35-
/// both async, whereas all metadata operations are sync. To create this structure, use the
36-
/// [`CacheBuilder`](crate::CacheBuilder).
35+
/// both async, whereas all metadata operations are sync. See [`CacheBuilder`](crate::CacheBuilder)
36+
/// for all customization options.
3737
///
3838
/// # Examples
3939
///
4040
/// ```rust
4141
/// # #[tokio::main(flavor = "current_thread")]
4242
/// # async fn main() {
43-
/// use forceps::CacheBuilder;
43+
/// use forceps::Cache;
4444
///
45-
/// let cache = CacheBuilder::new("./cache")
45+
/// let cache = Cache::new("./cache")
4646
/// .build()
4747
/// .await
4848
/// .unwrap();
@@ -55,6 +55,27 @@ pub struct Cache {
5555
}
5656

5757
impl Cache {
58+
/// Creates a new [`CacheBuilder`], which can be used to customize and create a [`Cache`]
59+
/// instance. This function is an alias for [`CacheBuilder::new`].
60+
///
61+
/// The `path` supplied is the base directory of the cache instance.
62+
///
63+
/// [`CacheBuilder`]: crate::CacheBuilder
64+
/// [`CacheBuilder::new`]: crate::CacheBuilder::new
65+
///
66+
/// # Examples
67+
///
68+
/// ```rust
69+
/// use forceps::Cache;
70+
///
71+
/// let builder = Cache::new("./cache");
72+
/// // Use other methods for configuration
73+
/// ```
74+
#[inline]
75+
pub fn new<P: AsRef<path::Path>>(path: P) -> crate::CacheBuilder {
76+
crate::CacheBuilder::new(path)
77+
}
78+
5879
/// Creates a new Cache instance based on the CacheBuilder
5980
pub(crate) async fn create(opts: Options) -> Result<Self> {
6081
// create the base directory for the cache
@@ -101,9 +122,9 @@ impl Cache {
101122
/// ```rust
102123
/// # #[tokio::main(flavor = "current_thread")]
103124
/// # async fn main() {
104-
/// use forceps::CacheBuilder;
125+
/// use forceps::Cache;
105126
///
106-
/// let cache = CacheBuilder::new("./cache")
127+
/// let cache = Cache::new("./cache")
107128
/// .build()
108129
/// .await
109130
/// .unwrap();
@@ -148,9 +169,9 @@ impl Cache {
148169
/// ```rust
149170
/// # #[tokio::main(flavor = "current_thread")]
150171
/// # async fn main() {
151-
/// use forceps::CacheBuilder;
172+
/// use forceps::Cache;
152173
///
153-
/// let cache = CacheBuilder::new("./cache")
174+
/// let cache = Cache::new("./cache")
154175
/// .build()
155176
/// .await
156177
/// .unwrap();
@@ -198,9 +219,9 @@ impl Cache {
198219
/// ```rust
199220
/// # #[tokio::main(flavor = "current_thread")]
200221
/// # async fn main() {
201-
/// use forceps::CacheBuilder;
222+
/// use forceps::Cache;
202223
///
203-
/// let cache = CacheBuilder::new("./cache")
224+
/// let cache = Cache::new("./cache")
204225
/// .build()
205226
/// .await
206227
/// .unwrap();
@@ -253,9 +274,9 @@ impl Cache {
253274
/// ```rust
254275
/// # #[tokio::main(flavor = "current_thread")]
255276
/// # async fn main() {
256-
/// use forceps::CacheBuilder;
277+
/// use forceps::Cache;
257278
///
258-
/// let cache = CacheBuilder::new("./cache")
279+
/// let cache = Cache::new("./cache")
259280
/// .build()
260281
/// .await
261282
/// .unwrap();
@@ -265,6 +286,7 @@ impl Cache {
265286
/// assert_eq!(meta.get_size(), b"Hello World".len() as u64);
266287
/// # }
267288
/// ```
289+
#[inline]
268290
pub fn read_metadata<K: AsRef<[u8]>>(&self, key: K) -> Result<Metadata> {
269291
self.meta.get_metadata(key.as_ref())
270292
}
@@ -284,9 +306,9 @@ impl Cache {
284306
/// ```rust
285307
/// # #[tokio::main(flavor = "current_thread")]
286308
/// # async fn main() {
287-
/// use forceps::CacheBuilder;
309+
/// use forceps::Cache;
288310
///
289-
/// let cache = CacheBuilder::new("./cache")
311+
/// let cache = Cache::new("./cache")
290312
/// .build()
291313
/// .await
292314
/// .unwrap();
@@ -298,6 +320,7 @@ impl Cache {
298320
/// }
299321
/// # }
300322
/// ```
323+
#[inline]
301324
pub fn metadata_iter(&self) -> impl Iterator<Item = Result<(Vec<u8>, Metadata)>> {
302325
self.meta.metadata_iter()
303326
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
//! ```rust
3434
//! # #[tokio::main(flavor = "current_thread")]
3535
//! # async fn main() {
36-
//! use forceps::CacheBuilder;
36+
//! use forceps::Cache;
3737
//!
38-
//! let cache = CacheBuilder::new("./cache")
38+
//! let cache = Cache::new("./cache")
3939
//! .build()
4040
//! .await
4141
//! .unwrap();

src/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ pub type Md5Bytes = [u8; 16];
1616
/// ```rust
1717
/// # #[tokio::main(flavor = "current_thread")]
1818
/// # async fn main() {
19-
/// use forceps::CacheBuilder;
19+
/// use forceps::Cache;
2020
///
21-
/// let cache = CacheBuilder::new("./cache")
21+
/// let cache = Cache::new("./cache")
2222
/// .build()
2323
/// .await
2424
/// .unwrap();

0 commit comments

Comments
 (0)