@@ -32,17 +32,17 @@ pub(crate) struct Options {
32
32
/// The main component of `forceps`, acts as the API for interacting with the on-disk API.
33
33
///
34
34
/// 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 .
37
37
///
38
38
/// # Examples
39
39
///
40
40
/// ```rust
41
41
/// # #[tokio::main(flavor = "current_thread")]
42
42
/// # async fn main() {
43
- /// use forceps::CacheBuilder ;
43
+ /// use forceps::Cache ;
44
44
///
45
- /// let cache = CacheBuilder ::new("./cache")
45
+ /// let cache = Cache ::new("./cache")
46
46
/// .build()
47
47
/// .await
48
48
/// .unwrap();
@@ -55,6 +55,27 @@ pub struct Cache {
55
55
}
56
56
57
57
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
+
58
79
/// Creates a new Cache instance based on the CacheBuilder
59
80
pub ( crate ) async fn create ( opts : Options ) -> Result < Self > {
60
81
// create the base directory for the cache
@@ -101,9 +122,9 @@ impl Cache {
101
122
/// ```rust
102
123
/// # #[tokio::main(flavor = "current_thread")]
103
124
/// # async fn main() {
104
- /// use forceps::CacheBuilder ;
125
+ /// use forceps::Cache ;
105
126
///
106
- /// let cache = CacheBuilder ::new("./cache")
127
+ /// let cache = Cache ::new("./cache")
107
128
/// .build()
108
129
/// .await
109
130
/// .unwrap();
@@ -148,9 +169,9 @@ impl Cache {
148
169
/// ```rust
149
170
/// # #[tokio::main(flavor = "current_thread")]
150
171
/// # async fn main() {
151
- /// use forceps::CacheBuilder ;
172
+ /// use forceps::Cache ;
152
173
///
153
- /// let cache = CacheBuilder ::new("./cache")
174
+ /// let cache = Cache ::new("./cache")
154
175
/// .build()
155
176
/// .await
156
177
/// .unwrap();
@@ -198,9 +219,9 @@ impl Cache {
198
219
/// ```rust
199
220
/// # #[tokio::main(flavor = "current_thread")]
200
221
/// # async fn main() {
201
- /// use forceps::CacheBuilder ;
222
+ /// use forceps::Cache ;
202
223
///
203
- /// let cache = CacheBuilder ::new("./cache")
224
+ /// let cache = Cache ::new("./cache")
204
225
/// .build()
205
226
/// .await
206
227
/// .unwrap();
@@ -253,9 +274,9 @@ impl Cache {
253
274
/// ```rust
254
275
/// # #[tokio::main(flavor = "current_thread")]
255
276
/// # async fn main() {
256
- /// use forceps::CacheBuilder ;
277
+ /// use forceps::Cache ;
257
278
///
258
- /// let cache = CacheBuilder ::new("./cache")
279
+ /// let cache = Cache ::new("./cache")
259
280
/// .build()
260
281
/// .await
261
282
/// .unwrap();
@@ -265,6 +286,7 @@ impl Cache {
265
286
/// assert_eq!(meta.get_size(), b"Hello World".len() as u64);
266
287
/// # }
267
288
/// ```
289
+ #[ inline]
268
290
pub fn read_metadata < K : AsRef < [ u8 ] > > ( & self , key : K ) -> Result < Metadata > {
269
291
self . meta . get_metadata ( key. as_ref ( ) )
270
292
}
@@ -284,9 +306,9 @@ impl Cache {
284
306
/// ```rust
285
307
/// # #[tokio::main(flavor = "current_thread")]
286
308
/// # async fn main() {
287
- /// use forceps::CacheBuilder ;
309
+ /// use forceps::Cache ;
288
310
///
289
- /// let cache = CacheBuilder ::new("./cache")
311
+ /// let cache = Cache ::new("./cache")
290
312
/// .build()
291
313
/// .await
292
314
/// .unwrap();
@@ -298,6 +320,7 @@ impl Cache {
298
320
/// }
299
321
/// # }
300
322
/// ```
323
+ #[ inline]
301
324
pub fn metadata_iter ( & self ) -> impl Iterator < Item = Result < ( Vec < u8 > , Metadata ) > > {
302
325
self . meta . metadata_iter ( )
303
326
}
0 commit comments