diff --git a/src/lib.rs b/src/lib.rs index 635b21a..8910cf6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/options.rs b/src/options.rs index ad527ae..ba76cc8 100644 --- a/src/options.rs +++ b/src/options.rs @@ -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 { + /// 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 { let shards = self.shards.unwrap_or_else(|| available_parallelism() * 4);