pub struct MutationResource<V, T, E = QueryError> { /* private fields */ }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>
impl<V, T, E> MutationResource<V, T, E>
Sourcepub fn new(retry_policy: RetryPolicy) -> Self
pub fn new(retry_policy: RetryPolicy) -> Self
Create a new mutation resource with the given retry policy.
Sourcepub fn status(&self) -> MutationStatus
pub fn status(&self) -> MutationStatus
Current status.
Sourcepub fn retry_count(&self) -> u32
pub fn retry_count(&self) -> u32
Current retry count.
Sourcepub fn cancelled_count(&self) -> u64
pub fn cancelled_count(&self) -> u64
Number of times this mutation has been cancelled.
Sourcepub fn retry_policy(&self) -> &RetryPolicy
pub fn retry_policy(&self) -> &RetryPolicy
The retry policy.
Sourcepub fn set_retry_policy(&mut self, policy: RetryPolicy)
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.
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Whether the mutation is currently loading.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Whether the mutation succeeded.
Sourcepub fn is_failure(&self) -> bool
pub fn is_failure(&self) -> bool
Whether the mutation failed.
Sourcepub fn with_key(self, key: QueryKey) -> Self
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.
Sourcepub fn begin(&mut self, variables: V)
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.
Sourcepub fn complete_success(&mut self, data: T)
pub fn complete_success(&mut self, data: T)
Complete successfully.
Sourcepub fn complete_failure(&mut self, error: E)
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.
Sourcepub fn should_retry(&self) -> bool
pub fn should_retry(&self) -> bool
Whether another retry is allowed.
Sourcepub fn retry(&mut self) -> bool
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.
Sourcepub fn signal(&self) -> Option<&QuerySignal>
pub fn signal(&self) -> Option<&QuerySignal>
The cancellation signal.
Sourcepub fn increment_retry(&mut self)
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.
Sourcepub fn prepare_retry(&mut self)
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.
Sourcepub fn reset_retry_count(&mut self)
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.
Sourcepub fn cancel(&mut self, error: E)
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>
impl<V: Clone, T: Clone, E: Clone> Clone for MutationResource<V, T, E>
Source§fn clone(&self) -> MutationResource<V, T, E>
fn clone(&self) -> MutationResource<V, T, E>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'de, V, T, E> Deserialize<'de> for MutationResource<V, T, E>
impl<'de, V, T, E> Deserialize<'de> for MutationResource<V, T, E>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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.
impl<V: 'static, T: 'static, E: 'static> ObservableResource for MutationResource<V, T, E>
client only.type Status = MutationStatus
fn observable_status(&self) -> MutationStatus
Source§impl<V, T, E> Serialize for MutationResource<V, T, E>
impl<V, T, E> Serialize for MutationResource<V, T, E>
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>
impl<V, T, E> RefUnwindSafe for MutationResource<V, T, E>
impl<V, T, E> Send for MutationResource<V, T, E>
impl<V, T, E> Sync for MutationResource<V, T, E>
impl<V, T, E> Unpin for MutationResource<V, T, E>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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