Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub use equivalent::Equivalent;
#[cfg(all(test, feature = "shuttle"))]
mod shuttle_tests;

pub use options::{Options, OptionsBuilder};
pub use options::{Error as OptionsError, Options, OptionsBuilder};

#[cfg(feature = "custom-hasher")]
type DefaultHasherImpl = foldhash::quality::RandomState;
Expand Down
18 changes: 18 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ impl OptionsBuilder {
}

/// Builds an `Options` struct which can be used in the `Cache::with_options` constructor.
///
/// Returns [OptionsError](crate::OptionsError) if required capacities are missing.
///
/// ```
/// use quick_cache::{Options, OptionsBuilder, OptionsError};
///
/// fn options(capacity: u64) -> Result<Options, OptionsError> {
/// OptionsBuilder::new()
/// .estimated_items_capacity(10)
/// .weight_capacity(capacity)
/// .build()
/// }
///
/// assert!(options(10).is_ok());
/// let error: OptionsError = OptionsBuilder::new().build().unwrap_err();
/// assert_eq!(error.to_string(), "weight_capacity is not set");
/// let _: &dyn std::error::Error = &error;
/// ```
#[inline]
pub fn build(&self) -> Result<Options, Error> {
let shards = self.shards.unwrap_or_else(|| available_parallelism() * 4);
Expand Down
Loading