pub struct ReadOnlyCacheBuilder { /* private fields */ }
Expand description
Construct a ReadOnlyCache
with this builder. The resulting
cache will access each constituent cache directory in the order
they were added.
The default builder is a fresh builder with no constituent cache and no consistency check function.
Implementations§
Source§impl ReadOnlyCacheBuilder
impl ReadOnlyCacheBuilder
Sourcepub fn consistency_checker(
&mut self,
checker: impl Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe + Sized + 'static,
) -> &mut Self
pub fn consistency_checker( &mut self, checker: impl Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe + Sized + 'static, ) -> &mut Self
Sets the consistency checker function: when the function is
provided, the ReadOnlyCache
will keep searching after the
first cache hit, and compare subsequent hits with the first
one by calling checker
. The checker
function should
return Ok(())
if the two files are compatible (identical),
and Err
otherwise.
Kismet will propagate the error on mismatch.
Sourcepub fn byte_equality_checker(&mut self) -> &mut Self
pub fn byte_equality_checker(&mut self) -> &mut Self
Sets the consistency checker function to
crate::byte_equality_checker
: the contents of all cache
hits must be bytewise identical, without considering any
metadata.
Sourcepub fn panicking_byte_equality_checker(&mut self) -> &mut Self
pub fn panicking_byte_equality_checker(&mut self) -> &mut Self
Sets the consistency checker function to
crate::panicking_byte_equality_checker
: the contents of
all cache hits must be bytewise identical, without considering
any metadata, and the call will panic on mismatch.
Sourcepub fn clear_consistency_checker(&mut self) -> &mut Self
pub fn clear_consistency_checker(&mut self) -> &mut Self
Removes the consistency checker function, if any.
Sourcepub fn arc_consistency_checker(
&mut self,
checker: Option<Arc<dyn Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe>>,
) -> &mut Self
pub fn arc_consistency_checker( &mut self, checker: Option<Arc<dyn Fn(&mut File, &mut File) -> Result<()> + Sync + Send + RefUnwindSafe + UnwindSafe>>, ) -> &mut Self
Sets the consistency checker function. None
clears the
checker function. See
ReadOnlyCacheBuilder::consistency_checker
.
Sourcepub fn cache(&mut self, path: impl AsRef<Path>, num_shards: usize) -> &mut Self
pub fn cache(&mut self, path: impl AsRef<Path>, num_shards: usize) -> &mut Self
Adds a new cache directory at path
to the end of the cache
builder’s search list.
Adds a plain cache directory if num_shards <= 1
, and an
actual sharded directory otherwise.
Sourcepub fn plain(&mut self, path: impl AsRef<Path>) -> &mut Self
pub fn plain(&mut self, path: impl AsRef<Path>) -> &mut Self
Adds a new plain cache directory at path
to the end of the
cache builder’s search list. A plain cache directory is
merely a directory of files where the files’ names match their
key’s name.
Sourcepub fn plain_caches<P>(
&mut self,
paths: impl IntoIterator<Item = P>,
) -> &mut Self
pub fn plain_caches<P>( &mut self, paths: impl IntoIterator<Item = P>, ) -> &mut Self
Adds a new plain cache directory for each path in paths
.
The caches are appended in order to the end of the cache
builder’s search list.
Sourcepub fn sharded(
&mut self,
path: impl AsRef<Path>,
num_shards: usize,
) -> &mut Self
pub fn sharded( &mut self, path: impl AsRef<Path>, num_shards: usize, ) -> &mut Self
Adds a new sharded cache directory at path
to the end of the
cache builder’s search list.
Sourcepub fn take(&mut self) -> Self
pub fn take(&mut self) -> Self
Returns the contents of self
as a fresh value; self
is
reset to the default empty builder state. This makes it
possible to declare simple configurations in a single
expression, with .take().build()
.
Sourcepub fn build(self) -> ReadOnlyCache
pub fn build(self) -> ReadOnlyCache
Returns a fresh ReadOnlyCache
for the builder’s search list
of constituent cache directories.