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§
Sourcefn state(&self) -> DeviceState
fn state(&self) -> DeviceState
Get the current lifecycle state.
Sourcefn 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 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.
Provided Methods§
Sourcefn is_operational(&self) -> bool
fn is_operational(&self) -> bool
Check if the device is in an operational state.
Sourcefn can_accept_requests(&self) -> bool
fn can_accept_requests(&self) -> bool
Check if the device can accept requests.
Sourcefn 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 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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".