Skip to main content

Operation

Struct Operation 

Source
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: Identity

The logical identity; an empty namespace inherits the instance’s.

§policy: Policy

Static caching policy, validated before execution.

§budget: SourceBudget

The 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>

Source

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>

Source

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.

Source

pub fn policy(self, policy: Policy) -> Self

Replace the static policy.

Source

pub fn budget(self, budget: SourceBudget) -> Self

Replace the source deadline.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T> Clone for Operation<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Operation<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Operation<T>

§

impl<T> !UnwindSafe for Operation<T>

§

impl<T> Freeze for Operation<T>

§

impl<T> Send for Operation<T>

§

impl<T> Sync for Operation<T>

§

impl<T> Unpin for Operation<T>

§

impl<T> UnsafeUnpin for Operation<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.