pub trait Feattles: FeattlesPrivate {
    // Required methods
    fn new(persistence: Arc<dyn Persist>) -> Self;
    fn persistence(&self) -> &Arc<dyn Persist>;
    fn keys(&self) -> &'static [&'static str];
    fn definition(&self, key: &str) -> Option<FeattleDefinition>;

    // Provided methods
    fn last_reload(&self) -> LastReload { ... }
    fn current_values(&self) -> Option<MappedRwLockReadGuard<'_, CurrentValues>> { ... }
    fn reload<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<(), BoxError>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn update<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: Value,
        modified_by: String
    ) -> Pin<Box<dyn Future<Output = Result<(), UpdateError>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn definitions(&self) -> Vec<FeattleDefinition> { ... }
    fn history<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str
    ) -> Pin<Box<dyn Future<Output = Result<ValueHistory, HistoryError>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

The main trait of this crate.

The struct created with feattles! will implement this trait in addition to a method for each feattle. Read more at the crate documentation.

Required Methods§

source

fn new(persistence: Arc<dyn Persist>) -> Self

Create a new feattles instance, using the given persistence layer logic.

All feattles will start with their default values. You can force an initial synchronization with Feattles::update.

source

fn persistence(&self) -> &Arc<dyn Persist>

Return a shared reference to the persistence layer.

source

fn keys(&self) -> &'static [&'static str]

The list of all available keys.

source

fn definition(&self, key: &str) -> Option<FeattleDefinition>

Describe one specific feattle, returning None if the feattle with the given name does not exist.

Provided Methods§

source

fn last_reload(&self) -> LastReload

Return details of the last time the data was synchronized by calling Feattles::reload().

source

fn current_values(&self) -> Option<MappedRwLockReadGuard<'_, CurrentValues>>

Return a reference to the last synchronized data. The reference is behind a read-write lock and will block any update until it is dropped. None is returned if a successful synchronization have never happened.

source

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

Reload the current feattles’ data from the persistence layer, propagating any errors produced by it.

If any of the feattle values fail to be parsed from previously persisted values, their updates will be skipped. Other feattles that parsed successfully will still be updated. In this case, a log::error! will be generated for each time it occurs.

source

fn update<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, value: Value, modified_by: String ) -> Pin<Box<dyn Future<Output = Result<(), UpdateError>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update a single feattle, passing the new value (in JSON representation) and the user that is associated with this change. The change will be persisted directly.

While the update is happening, the new value will already be observable from other execution tasks or threads. However, if the update fails, the change will be rolled back.

Consistency

To avoid operating on stale data, before doing an update the caller should usually call Feattles::reload() to ensure data is current.

source

fn definitions(&self) -> Vec<FeattleDefinition>

Return the definition for all the feattles.

source

fn history<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<ValueHistory, HistoryError>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Return the history for a single feattle. It can be potentially empty (not entries).

Implementors§