pub struct Store {
store: Arc<dyn StoreBackend>,
}
Expand description
A wrapper around any StoreBackend
, providing access to the underlying
store along some with extra things like logging.
Fields§
§store: Arc<dyn StoreBackend>
Implementations§
Source§impl Store
impl Store
Sourcepub async fn new(
store_type: BackendType,
config: &HashMap<String, String>,
) -> Result<Self>
pub async fn new( store_type: BackendType, config: &HashMap<String, String>, ) -> Result<Self>
Create a new instance of this Store
. Configuration is
backend-specific and is provided as a HashMap
from string keys to
string values, that are parsed by the backend as needed.
§Errors
This function returns an error if the store could not be initialized. This may happen if the configuration is invalid or for other backend-specific reasons (such as a file not being createable or a network connection not being establishable, etc.).
Sourcepub fn backend_name(&self) -> &'static str
pub fn backend_name(&self) -> &'static str
Get the underlying implementation’s name. The name (used in e.g. the configuration) of the backend store implementing this trait must be a human-readable name using only ‘a’-‘z’, ‘0’-‘9’, and ‘_’.
Sourcepub async fn get_redirect(&self, from: Id) -> Result<Option<Link>>
pub async fn get_redirect(&self, from: Id) -> Result<Option<Link>>
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.
Sourcepub async fn set_redirect(&self, from: Id, to: Link) -> Result<Option<Link>>
pub async fn set_redirect(&self, from: Id, to: Link) -> Result<Option<Link>>
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.
Sourcepub async fn rem_redirect(&self, from: Id) -> Result<Option<Link>>
pub async fn rem_redirect(&self, from: Id) -> Result<Option<Link>>
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.
Sourcepub async fn get_vanity(&self, from: Normalized) -> Result<Option<Id>>
pub async fn get_vanity(&self, from: Normalized) -> Result<Option<Id>>
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.
Sourcepub async fn set_vanity(&self, from: Normalized, to: Id) -> Result<Option<Id>>
pub async fn set_vanity(&self, from: Normalized, to: Id) -> Result<Option<Id>>
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.
Sourcepub async fn rem_vanity(&self, from: Normalized) -> Result<Option<Id>>
pub async fn rem_vanity(&self, from: Normalized) -> Result<Option<Id>>
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.
Sourcepub async fn get_statistics(
&self,
description: StatisticDescription,
) -> Result<impl Iterator<Item = (Statistic, StatisticValue)>>
pub async fn get_statistics( &self, description: StatisticDescription, ) -> Result<impl Iterator<Item = (Statistic, StatisticValue)>>
Get statistics’ values by their description. Returns all matching statistics and their values for the provided statistic description. Statistics not having been collected is not an error, if no matching statistics are found, an empty iterator is returned.
§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.
Sourcepub fn incr_statistics<I>(&self, statistics: I)
pub fn incr_statistics<I>(&self, statistics: I)
Increment multiple statistics’ count for the given id and/or vanity path. Each of the provided statistics’ values for the provided id and vanity path are incremented by 1 in a spawned tokio task in the background.
§Error
This function failing in any way is not considered an error, because statistics are done on a best-effort basis. However, any errors that occur are logged.
Sourcepub async fn rem_statistics(
&self,
description: StatisticDescription,
) -> Result<impl Iterator<Item = (Statistic, StatisticValue)>>
pub async fn rem_statistics( &self, description: StatisticDescription, ) -> Result<impl Iterator<Item = (Statistic, StatisticValue)>>
Remove statistics by their description. Deletes all statistics that match the provided description 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 iterator is returned.
§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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Store
impl !RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl !UnwindSafe for Store
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request