pub struct MovementGuard { /* private fields */ }Expand description
A RAII helper class to ensure that pending movements get marked as finished in case an error occurs. You can construct a guard for an existing Movement with MovementGuard::new. Alternatively, a MovementGuard can be coupled to a movement using MovementGuard::new.
When the MovementGuard is dropped from the stack, it will finalize the movement according to the configured OnDropStatus unless MovementGuard::success has already been called.
Implementations§
Source§impl<'a> MovementGuard
impl<'a> MovementGuard
Sourcepub fn new(
id: MovementId,
manager: Arc<MovementManager>,
on_drop: OnDropStatus,
) -> Self
pub fn new( id: MovementId, manager: Arc<MovementManager>, on_drop: OnDropStatus, ) -> Self
Constructs a MovementGuard to manage a pre-existing Movement.
Parameters:
- id: The ID of the Movement to update.
- manager: A reference to the MovementManager so the guard can update the Movement.
- on_drop: Determines what status the movement will be set to when the guard is dropped.
Sourcepub fn id(&self) -> MovementId
pub fn id(&self) -> MovementId
Gets the MovementId stored by this guard.
Sourcepub fn set_on_drop_status(&mut self, status: OnDropStatus)
pub fn set_on_drop_status(&mut self, status: OnDropStatus)
Sets a different OnDropStatus to apply to the movement upon dropping the MovementGuard.
Parameters:
- on_drop: Determines what status the movement will be set to when the guard is dropped.
Sourcepub async fn apply_update(
&self,
update: MovementUpdate,
) -> Result<(), MovementError>
pub async fn apply_update( &self, update: MovementUpdate, ) -> Result<(), MovementError>
Applies an update to the managed Movement.
See MovementManager::update_movement for more information.
Parameters:
- update: Specifies properties to set on the movement.
Optionfields will be ignored if they areNone.Somewill result in that particular field being overwritten.
Sourcepub async fn cancel(&mut self) -> Result<(), MovementError>
pub async fn cancel(&mut self) -> Result<(), MovementError>
Same as MovementGuard::success but sets Movement::status to MovementStatus::Canceled.
Sourcepub async fn fail(&mut self) -> Result<(), MovementError>
pub async fn fail(&mut self) -> Result<(), MovementError>
Same as MovementGuard::success but sets Movement::status to MovementStatus::Failed.
Sourcepub async fn success(&mut self) -> Result<(), MovementError>
pub async fn success(&mut self) -> Result<(), MovementError>
Finalizes a movement, setting it to MovementStatus::Successful. If the MovementGuard is dropped after calling this function, no further changes will be made to the Movement.
See MovementManager::finish_movement for more information.
Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Prevents the guard from making further changes to the movement after being dropped. Manual actions such as MovementGuard::apply_update will continue to work.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MovementGuard
impl !RefUnwindSafe for MovementGuard
impl Send for MovementGuard
impl Sync for MovementGuard
impl Unpin for MovementGuard
impl !UnwindSafe for MovementGuard
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request