pub struct VarianceBuilder<'a> { /* private fields */ }
Expand description
A builder for variance keys, used for distinguishing multiple cached assets at the same URL. This is intended to be easily passed to helper functions, which can each populate a portion of the variance.
Implementations§
Source§impl<'a> VarianceBuilder<'a>
impl<'a> VarianceBuilder<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty variance key. Has no variance by default - add some variance using
Self::add_value
.
Sourcepub fn add_value(
&mut self,
name: &'a str,
value: &'a (impl AsRef<[u8]> + ?Sized),
)
pub fn add_value( &mut self, name: &'a str, value: &'a (impl AsRef<[u8]> + ?Sized), )
Add a byte string to the variance key. Not sensitive to insertion order.
value
is intended to take either &str
or &[u8]
.
Sourcepub fn add_owned_value(&mut self, name: &'a str, value: Vec<u8>)
pub fn add_owned_value(&mut self, name: &'a str, value: Vec<u8>)
Move a byte string to the variance key. Not sensitive to insertion order. Useful when writing helper functions which generate a value then add said value to the VarianceBuilder. Without this, the helper function would have to move the value to the calling function to extend its lifetime to at least match the VarianceBuilder.
Sourcepub fn has_variance(&self) -> bool
pub fn has_variance(&self) -> bool
Check whether this variance key actually has variance, or just refers to the root asset
Sourcepub fn finalize(self) -> Option<HashBinary>
pub fn finalize(self) -> Option<HashBinary>
Hash this variance key. Returns None
if Self::has_variance
is false.