Skip to main content

DeviceLifecycle

Trait DeviceLifecycle 

Source
pub trait DeviceLifecycle: Send + Sync {
    // Required methods
    fn state(&self) -> DeviceState;
    fn initialize<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn start<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn is_operational(&self) -> bool { ... }
    fn can_accept_requests(&self) -> bool { ... }
    fn on_error<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _error: &'life1 Error,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn recover<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Lifecycle management trait for devices.

This trait separates lifecycle concerns from regular device operations, making it easier to implement custom lifecycle behavior and testing.

Required Methods§

Source

fn state(&self) -> DeviceState

Get the current lifecycle state.

Source

fn initialize<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Initialize the device.

This should set up any necessary resources and move the device from Uninitialized to Offline state.

Source

fn start<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Start the device.

This should make the device operational and move it to Online state.

Source

fn stop<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Stop the device.

This should gracefully stop the device and move it to Offline state.

Provided Methods§

Source

fn is_operational(&self) -> bool

Check if the device is in an operational state.

Source

fn can_accept_requests(&self) -> bool

Check if the device can accept requests.

Source

fn on_error<'life0, 'life1, 'async_trait>( &'life0 mut self, _error: &'life1 Error, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Handle errors during operation.

This is called when an error occurs during device operation. The default implementation transitions to Error state.

Source

fn recover<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Attempt to recover from an error state.

Returns true if recovery was successful.

Implementors§