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_movement.
When the MovementGuard is dropped from the stack, it will finalize the movement according to the configured OnDropStatus unless MovementGuard::finish has already been called.
Implementations§
Source§impl<'a> MovementGuard
impl<'a> MovementGuard
Sourcepub fn new(id: MovementId, manager: Arc<MovementManager>) -> Self
pub fn new(id: MovementId, manager: Arc<MovementManager>) -> 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.
Sourcepub async fn new_movement(
manager: Arc<MovementManager>,
subsystem_id: SubsystemId,
movement_kind: String,
) -> Result<Self, MovementError>
pub async fn new_movement( manager: Arc<MovementManager>, subsystem_id: SubsystemId, movement_kind: String, ) -> Result<Self, MovementError>
Constructs a MovementGuard and creates a new Movement for the guard to manage.
See MovementManager::new_movement for more information.
Parameters:
- manager: A reference to the MovementManager so the guard can update the Movement.
- subsystem_id: The ID of the subsystem that wishes to start a new movement.
- movement_kind: A descriptor for the type of movement being performed, e.g. “send”, “receive”, “round”.
Sourcepub async fn new_movement_at(
manager: Arc<MovementManager>,
subsystem_id: SubsystemId,
movement_kind: String,
at: DateTime<Local>,
) -> Result<Self, MovementError>
pub async fn new_movement_at( manager: Arc<MovementManager>, subsystem_id: SubsystemId, movement_kind: String, at: DateTime<Local>, ) -> Result<Self, MovementError>
Similar to MovementGuard::new_movement with the ability to set a custom timestamp.
Parameters:
- manager: A reference to the MovementManager so the guard can update the Movement.
- subsystem_id: The ID of the subsystem that wishes to start a new movement.
- movement_kind: A descriptor for the type of movement being performed, e.g. “send”, “receive”, “round”.
- at: The timestamp to set the [MovementTimestamp::created_at] field to.
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 apply_update_at(
&self,
update: MovementUpdate,
at: DateTime<Local>,
) -> Result<(), MovementError>
pub async fn apply_update_at( &self, update: MovementUpdate, at: DateTime<Local>, ) -> Result<(), MovementError>
Similar to MovementGuard::apply_update with the ability to set a custom timestamp.
Parameters:
- update: Specifies properties to set on the movement.
Optionfields will be ignored if they areNone.Somewill result in that particular field being overwritten. - at: The timestamp to set the [MovementTimestamp::completed_at] field to.
Sourcepub async fn finish(
&mut self,
status: MovementStatus,
) -> Result<(), MovementError>
pub async fn finish( &mut self, status: MovementStatus, ) -> Result<(), MovementError>
Finalizes a movement, setting it to the given MovementStatus. 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.
Parameters:
- status: The final MovementStatus to set. Must not be MovementStatus::Pending.
Sourcepub async fn finish_at(
&mut self,
status: MovementStatus,
at: DateTime<Local>,
) -> Result<(), MovementError>
pub async fn finish_at( &mut self, status: MovementStatus, at: DateTime<Local>, ) -> Result<(), MovementError>
Finalizes a movement, setting it to the given MovementStatus. 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.
Parameters:
- status: The final MovementStatus to set. Must not be MovementStatus::Pending.
- at: The timestamp to set the [MovementTimestamp::completed_at] field to.
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