pub struct Operation<T> {
pub identity: Identity,
pub policy: Policy,
pub budget: SourceBudget,
pub codec: Arc<dyn Codec<T>>,
pub comparator: Comparator<T>,
pub should_recover: Option<RecoveryPredicate>,
pub preview: Option<Preview<T>>,
pub mismatch_diff: Option<MismatchDiffHook<T>>,
/* private fields */
}Expand description
One inline cached call: its identity, static policy, budget and codecs.
Use it directly with
DialCache::get_or_load when a stable use
case is declared at the call site instead of being registered.
Fields§
§identity: IdentityThe logical identity; an empty namespace inherits the instance’s.
policy: PolicyStatic caching policy, validated before execution.
budget: SourceBudgetThe source deadline.
codec: Arc<dyn Codec<T>>Encodes and decodes values for the remote layer.
comparator: Comparator<T>Application equality for shadow validation.
should_recover: Option<RecoveryPredicate>Per-operation stale-recovery classifier. None defers to the
instance’s, which by default admits only the source deadline error.
preview: Option<Preview<T>>Renders the value fields of mismatch warnings; see Preview.
new sets the values’ JSON rendering, which also
feeds the built-in difference computation. A closure you set replaces
that JSON for the whole warning, so difference fields then come only
from a mismatch_diff hook. None logs no
values and leaves the operation without a JSON rendering, as one built
with with_codec is: a requested value field
is unavailable with a render_error outcome, and so are difference
fields without a hook.
mismatch_diff: Option<MismatchDiffHook<T>>Replaces the built-in difference computation of mismatch warnings.
None runs the built-in walk over the values’ JSON, which only an
operation built with new that keeps its default
preview has.
Implementations§
Source§impl<T: Serialize + DeserializeOwned + PartialEq + Send + Sync + 'static> Operation<T>
impl<T: Serialize + DeserializeOwned + PartialEq + Send + Sync + 'static> Operation<T>
Sourcepub fn new(identity: Identity) -> Self
pub fn new(identity: Identity) -> Self
An operation using the JSON codec, PartialEq shadow comparison and
the values’ JSON for mismatch warnings: its default
preview logs that JSON as the value fields, and the
built-in difference computation walks it. The JSON rendering stays
when the codec or comparator is replaced afterwards; a preview you set
replaces it, and None in place of the default removes it.
Source§impl<T: Send + Sync + 'static> Operation<T>
impl<T: Send + Sync + 'static> Operation<T>
Sourcepub fn with_codec(
identity: Identity,
codec: Arc<dyn Codec<T>>,
comparator: impl Fn(&T, &T) -> bool + Send + Sync + 'static,
) -> Self
pub fn with_codec( identity: Identity, codec: Arc<dyn Codec<T>>, comparator: impl Fn(&T, &T) -> bool + Send + Sync + 'static, ) -> Self
An operation with an explicit codec and comparator, for values that
are not serde JSON values. Mismatch warnings have no JSON rendering:
their value fields need a preview and their
difference fields a mismatch_diff hook, and a
field logged without one is unavailable with a render_error outcome.
A JSON renderer for such operations is tracked in
https://github.com/lan17/DialCache/issues/245.
Sourcepub fn budget(self, budget: SourceBudget) -> Self
pub fn budget(self, budget: SourceBudget) -> Self
Replace the source deadline.
Sourcepub fn should_recover(
self,
predicate: impl Fn(&Error) -> bool + Send + Sync + 'static,
) -> Self
pub fn should_recover( self, predicate: impl Fn(&Error) -> bool + Send + Sync + 'static, ) -> Self
Set the stale-recovery classifier for this operation, overriding the instance’s.
Sourcepub fn preview(
self,
preview: impl Fn(&T) -> Option<String> + Send + Sync + 'static,
) -> Self
pub fn preview( self, preview: impl Fn(&T) -> Option<String> + Send + Sync + 'static, ) -> Self
Set the text mismatch warnings log for each value in place of its
JSON; None from the closure logs the field as unavailable. Difference
fields then come only from a mismatch_diff
hook.
Sourcepub fn mismatch_diff(
self,
hook: impl Fn(&T, &T) -> Vec<MismatchEntry> + Send + Sync + 'static,
) -> Self
pub fn mismatch_diff( self, hook: impl Fn(&T, &T) -> Vec<MismatchEntry> + Send + Sync + 'static, ) -> Self
Replace the built-in difference computation of mismatch warnings; see
MismatchDiffHook.