Skip to main content

MutationResource

Struct MutationResource 

Source
pub struct MutationResource<V, T, E = QueryError> { /* private fields */ }
Available on crate feature core only.
Expand description

A mutation resource that tracks the state of a single mutation.

V is the variables (input) type, T is the success output type, and E is the error type.

Implementations§

Source§

impl<V, T, E> MutationResource<V, T, E>

Source

pub fn new(retry_policy: RetryPolicy) -> Self

Create a new mutation resource with the given retry policy.

Source

pub fn status(&self) -> MutationStatus

Current status.

Source

pub fn data(&self) -> Option<&T>

Most recent successful data.

Source

pub fn error(&self) -> Option<&E>

Most recent error.

Source

pub fn variables(&self) -> Option<&V>

Variables for the current or most recent mutation.

Source

pub fn retry_count(&self) -> u32

Current retry count.

Source

pub fn cancelled_count(&self) -> u64

Number of times this mutation has been cancelled.

Source

pub fn retry_policy(&self) -> &RetryPolicy

The retry policy.

Source

pub fn set_retry_policy(&mut self, policy: RetryPolicy)

Set the retry policy.

Mirrors QueryResource::set_retry_policy / InfiniteQueryResource::set_retry_policy for API consistency.

Source

pub fn is_loading(&self) -> bool

Whether the mutation is currently loading.

Source

pub fn is_idle(&self) -> bool

Whether the mutation is idle.

Source

pub fn is_success(&self) -> bool

Whether the mutation succeeded.

Source

pub fn is_failure(&self) -> bool

Whether the mutation failed.

Source

pub fn key(&self) -> Option<&QueryKey>

Optional query key for this mutation.

Source

pub fn with_key(self, key: QueryKey) -> Self

Associate a query key with this mutation.

Forward-compatibility hook: the hook layer does not currently set a key on mutations, so key remains None in production. Kept for callers that want to tag a mutation with a key for diagnostics/invalidation.

Source

pub fn begin(&mut self, variables: V)

Start a mutation with the given variables.

Transitions to Loading, stores variables, clears error, creates signal. Cancels any previous in-flight signal so a prior fetcher observes cancellation. Resets retry_count so each mutation invocation starts fresh, matching QueryResource’s behavior where the hook layer resets retries on success.

Source

pub fn complete_success(&mut self, data: T)

Complete successfully.

Source

pub fn complete_failure(&mut self, error: E)

Complete with failure.

Clears data so consumers do not see stale success data alongside a Failure status. Increments retry_count with saturating add to prevent wraparound.

Source

pub fn should_retry(&self) -> bool

Whether another retry is allowed.

Source

pub fn retry(&mut self) -> bool

Retry by transitioning back to Loading.

Only valid from Failure when retries remain. A fresh cancellation signal is created.

Source

pub fn reset(&mut self)

Reset to idle, clearing everything.

Source

pub fn signal(&self) -> Option<&QuerySignal>

The cancellation signal.

Source

pub fn increment_retry(&mut self)

Increment the retry counter.

Used by the mutation retry loop to track how many attempts have been made without transitioning through a terminal Failure state.

Source

pub fn prepare_retry(&mut self)

Prepare for a retry by refreshing the signal without transitioning through Failure.

Avoids a transient Failure status that would cause observers to see a brief Failure flash between retry attempts. The mutation stays in Loading state, the old signal is cancelled, and a fresh signal is created for the next attempt.

Source

pub fn reset_retry_count(&mut self)

Reset the retry counter to zero.

Called on terminal failure so that retry_count is clean for the next mutation invocation.

Source

pub fn cancel(&mut self, error: E)

Cancel the mutation.

Only has effect when the mutation is in Loading state. Returns without side effects if the mutation is already Idle, Success, or Failure, matching the QueryResource::cancel behavior where a no-op cancel is silent.

When effective, increments cancelled_count for diagnostics and sets status to Failure.

Trait Implementations§

Source§

impl<V: Clone, T: Clone, E: Clone> Clone for MutationResource<V, T, E>

Source§

fn clone(&self) -> MutationResource<V, T, E>

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<V: Debug, T: Debug, E: Debug> Debug for MutationResource<V, T, E>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de, V, T, E> Deserialize<'de> for MutationResource<V, T, E>
where V: Deserialize<'de>, T: Deserialize<'de>, E: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<V: Eq, T: Eq, E: Eq> Eq for MutationResource<V, T, E>

Source§

impl<V: 'static, T: 'static, E: 'static> ObservableResource for MutationResource<V, T, E>

Available on crate feature client only.
Source§

impl<V: PartialEq, T: PartialEq, E: PartialEq> PartialEq for MutationResource<V, T, E>

Source§

fn eq(&self, other: &MutationResource<V, T, E>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<V, T, E> Serialize for MutationResource<V, T, E>
where V: Serialize, T: Serialize, E: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<V: PartialEq, T: PartialEq, E: PartialEq> StructuralPartialEq for MutationResource<V, T, E>

Auto Trait Implementations§

§

impl<V, T, E> Freeze for MutationResource<V, T, E>
where Option<T>: Freeze, Option<E>: Freeze, Option<V>: Freeze,

§

impl<V, T, E> RefUnwindSafe for MutationResource<V, T, E>

§

impl<V, T, E> Send for MutationResource<V, T, E>
where Option<T>: Send, Option<E>: Send, Option<V>: Send,

§

impl<V, T, E> Sync for MutationResource<V, T, E>
where Option<T>: Sync, Option<E>: Sync, Option<V>: Sync,

§

impl<V, T, E> Unpin for MutationResource<V, T, E>
where Option<T>: Unpin, Option<E>: Unpin, Option<V>: Unpin,

§

impl<V, T, E> UnsafeUnpin for MutationResource<V, T, E>

§

impl<V, T, E> UnwindSafe for MutationResource<V, T, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more