[][src]Trait pantry::Perishable

pub trait Perishable: Send + 'static {
#[must_use]    fn perished<'life0, 'async_trait>(
        &'life0 mut self
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
; }

This is the trait that values must implement in order to be stored in the Pantry. Note that since the trait has an asynchronous method, currently the async_trait attribute from the async-trait crate must be added to implementations.

Examples

use async_trait::async_trait;
use pantry::Perishable;

struct SpyOrders(String);

#[async_trait]
impl Perishable for SpyOrders {
    async fn perished(&mut self) {
        // This message will self-destruct after
        // sitting in the pantry for 5 seconds!
        async_std::future::timeout(
            std::time::Duration::from_secs(5),
            futures::future::pending::<()>(),
        )
        .await
        .unwrap_or(())
    }
}

Required methods

#[must_use]fn perished<'life0, 'async_trait>(
    &'life0 mut self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

This asynchronous function should complete once the value has "decayed" or become unusable or unsuitable for reuse. The worker thread of the Pantry runs this future to completion, automatically dropping the value if it completes.

Note that this is an asynchronous trait method. Currently, the async_trait attribute from the async-trait crate is used to realize this specification.

Loading content...

Implementors

Loading content...