Trait StoreBackend

Source
pub trait StoreBackend:
    Debug
    + Send
    + Sync {
    // Required methods
    fn store_type() -> BackendType
       where Self: Sized;
    fn get_store_type(&self) -> BackendType;
    fn new<'life0, 'async_trait>(
        config: &'life0 HashMap<String, String>,
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait,
             'life0: 'async_trait;
    fn get_redirect<'life0, 'async_trait>(
        &'life0 self,
        from: Id,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Link>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn set_redirect<'life0, 'async_trait>(
        &'life0 self,
        from: Id,
        to: Link,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Link>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn rem_redirect<'life0, 'async_trait>(
        &'life0 self,
        from: Id,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Link>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_vanity<'life0, 'async_trait>(
        &'life0 self,
        from: Normalized,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Id>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn set_vanity<'life0, 'async_trait>(
        &'life0 self,
        from: Normalized,
        to: Id,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Id>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn rem_vanity<'life0, 'async_trait>(
        &'life0 self,
        from: Normalized,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Id>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn get_statistics<'life0, 'async_trait>(
        &'life0 self,
        _description: StatisticDescription,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(Statistic, StatisticValue)>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn incr_statistic<'life0, 'async_trait>(
        &'life0 self,
        _statistic: Statistic,
    ) -> Pin<Box<dyn Future<Output = Result<Option<StatisticValue>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn rem_statistics<'life0, 'async_trait>(
        &'life0 self,
        _description: StatisticDescription,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(Statistic, StatisticValue)>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

The redirect, vanity path, and statistics store trait used by links.

Required Methods§

Source

fn store_type() -> BackendType
where Self: Sized,

Get this implementation’s backend store type. This is used in e.g. the configuration.

Source

fn get_store_type(&self) -> BackendType

Get this implementation’s backend store type. This can be used on trait objects, but is otherwise equivalent to calling Self::store_type().

Source

fn new<'life0, 'async_trait>( config: &'life0 HashMap<String, String>, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: Sized + 'async_trait, 'life0: 'async_trait,

Create a new instance of this StoreBackend. Configuration is provided as a collection of pico-args arguments beginning with --store-. For details about configuring each store backend, see that backend’s documentation.

Source

fn get_redirect<'life0, 'async_trait>( &'life0 self, from: Id, ) -> Pin<Box<dyn Future<Output = Result<Option<Link>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a redirect. Returns the full to link corresponding to the from links ID. A link not existing is not an error, if no matching link is found, Ok(None) is returned.

§Error

An error is only returned if something actually fails; if we don’t know if a link exists or not, or what it is. A link not existing is not considered an error.

Source

fn set_redirect<'life0, 'async_trait>( &'life0 self, from: Id, to: Link, ) -> Pin<Box<dyn Future<Output = Result<Option<Link>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Set a redirect. from is the ID of the link, while to is the full destination link. If a mapping with this ID already exists, it must be changed to the new one, returning the old one.

§Storage Guarantees

If an Ok is returned, the new value was definitely set / processed / saved, and will be available on next request. If an Err is returned, the value must not have been set / modified, insofar as that is possible to determine from the backend.

Source

fn rem_redirect<'life0, 'async_trait>( &'life0 self, from: Id, ) -> Pin<Box<dyn Future<Output = Result<Option<Link>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove a redirect. from is the ID of the links link to be removed. Returns the old value of the mapping or None if there was no such mapping.

§Storage Guarantees

If an Ok is returned, the new value was definitely removed / processed / saved, and will be unavailable on next request. If an Err is returned, the value must not have been removed / modified, insofar as that is possible to determine from the backend.

Source

fn get_vanity<'life0, 'async_trait>( &'life0 self, from: Normalized, ) -> Pin<Box<dyn Future<Output = Result<Option<Id>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a vanity path’s ID. Returns the ID of the to link corresponding to the from vanity path. An ID not existing is not an error, if no matching ID is found, None is returned.

§Error

An error is only returned if something actually fails; if we don’t know if a link exists or not, or what it is. A link not existing is not considered an error.

Source

fn set_vanity<'life0, 'async_trait>( &'life0 self, from: Normalized, to: Id, ) -> Pin<Box<dyn Future<Output = Result<Option<Id>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Set a vanity path for an ID. from is the vanity path of the links ID, while to is the ID itself. If a vanity link with this path already exists, it must be changed to the new one, returning the old one.

§Storage Guarantees

If an Ok is returned, the new value was definitely set / processed / saved, and will be available on next request. If an Err is returned, the value must not have been set / modified, insofar as that is possible to determine from the backend.

Source

fn rem_vanity<'life0, 'async_trait>( &'life0 self, from: Normalized, ) -> Pin<Box<dyn Future<Output = Result<Option<Id>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove a vanity path. from is the vanity path to be removed. Returns the old value of the mapping or None if there was no such mapping.

§Storage Guarantees

If an Ok is returned, the new value was definitely removed / processed / saved, and will be unavailable on next request. If an Err is returned, the value must not have been removed / modified, insofar as that is possible to determine from the backend.

Provided Methods§

Source

fn get_statistics<'life0, 'async_trait>( &'life0 self, _description: StatisticDescription, ) -> Pin<Box<dyn Future<Output = Result<Vec<(Statistic, StatisticValue)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get statistics’ values by their description. Returns all matching Statistics and their values for the provided StatisticDescription. Statistics not having been collected is not an error, if no matching statistics are found, an empty Vec is returned.

By default this function returns an empty Vec

§Error

An error is only returned if something fails when it should have worked. A statistic not existing or the store not supporting statistics is not considered an error.

Source

fn incr_statistic<'life0, 'async_trait>( &'life0 self, _statistic: Statistic, ) -> Pin<Box<dyn Future<Output = Result<Option<StatisticValue>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Increment a statistic’s count. The provided Statistic’s value is incremented by 1. Returns the new value of the statistic after the increment, or None if the statistic wasn’t recorded or its new value is not known.

By default this function does nothing and returns Ok(None)

§Error

An error is only returned if something fails when it should have worked. A statistic not being recorded (immediately or ever) is not considered and error.

Source

fn rem_statistics<'life0, 'async_trait>( &'life0 self, _description: StatisticDescription, ) -> Pin<Box<dyn Future<Output = Result<Vec<(Statistic, StatisticValue)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove statistics by their description. Deletes all Statistics that match the provided StatisticDescription and returns their values before they were deleted, if they’re available. A statistic not having been collected is not an error, if no matching statistics are found, an empty Vec is returned.

By default this function does nothing and returns an empty Vec

§Error

An error is only returned if something fails when it should have worked. A statistic not existing or the store not supporting statistics is not considered an error.

Implementors§

Source§

impl StoreBackend for links::store::Memory

Source§

impl StoreBackend for links::store::Redis