You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
storage: freeze the error type on BoxRepository
This avoids having to deal with traits bounds everywhere. It also moves the `boxed()` method to the PgRepository, because it was unnecessary to keep it on the `Repository` trait
This commit is contained in:
@ -104,6 +104,13 @@ impl Pagination {
|
||||
self
|
||||
}
|
||||
|
||||
/// Clear the before cursor
|
||||
#[must_use]
|
||||
pub const fn clear_before(mut self) -> Self {
|
||||
self.before = None;
|
||||
self
|
||||
}
|
||||
|
||||
/// Get items after the given cursor
|
||||
#[must_use]
|
||||
pub const fn after(mut self, id: Ulid) -> Self {
|
||||
@ -111,6 +118,13 @@ impl Pagination {
|
||||
self
|
||||
}
|
||||
|
||||
/// Clear the after cursor
|
||||
#[must_use]
|
||||
pub const fn clear_after(mut self) -> Self {
|
||||
self.after = None;
|
||||
self
|
||||
}
|
||||
|
||||
/// Process a page returned by a paginated query
|
||||
#[must_use]
|
||||
pub fn process<T>(&self, mut edges: Vec<T>) -> Page<T> {
|
||||
|
@ -34,7 +34,6 @@ use crate::{
|
||||
BrowserSessionRepository, UserEmailRepository, UserPasswordRepository,
|
||||
UserRecoveryRepository, UserRepository, UserTermsRepository,
|
||||
},
|
||||
MapErr,
|
||||
};
|
||||
|
||||
/// A [`Repository`] helps interacting with the underlying storage backend.
|
||||
@ -43,21 +42,6 @@ pub trait Repository<E>:
|
||||
where
|
||||
E: std::error::Error + Send + Sync + 'static,
|
||||
{
|
||||
/// Construct a (boxed) typed-erased repository
|
||||
fn boxed(self) -> BoxRepository<E>
|
||||
where
|
||||
Self: Sync + Sized + 'static,
|
||||
{
|
||||
Box::new(self)
|
||||
}
|
||||
|
||||
/// Map the error type of all the methods of a [`Repository`]
|
||||
fn map_err<Mapper>(self, mapper: Mapper) -> MapErr<Self, Mapper>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
MapErr::new(self, mapper)
|
||||
}
|
||||
}
|
||||
|
||||
/// An opaque, type-erased error
|
||||
@ -80,7 +64,7 @@ impl RepositoryError {
|
||||
}
|
||||
|
||||
/// A type-erased [`Repository`]
|
||||
pub type BoxRepository<E = RepositoryError> = Box<dyn Repository<E> + Send + Sync + 'static>;
|
||||
pub type BoxRepository = Box<dyn Repository<RepositoryError> + Send + Sync + 'static>;
|
||||
|
||||
/// A [`RepositoryTransaction`] can be saved or cancelled, after a series
|
||||
/// of operations.
|
||||
@ -113,7 +97,7 @@ pub trait RepositoryTransaction {
|
||||
/// repository is used at a time.
|
||||
///
|
||||
/// When adding a new repository, you should add a new method to this trait, and
|
||||
/// update the implementations for [`MapErr`] and [`Box<R>`] below.
|
||||
/// update the implementations for [`crate::MapErr`] and [`Box<R>`] below.
|
||||
///
|
||||
/// Note: this used to have generic associated types to avoid boxing all the
|
||||
/// repository traits, but that was removed because it made almost impossible to
|
||||
@ -218,7 +202,7 @@ pub trait RepositoryAccess: Send {
|
||||
}
|
||||
|
||||
/// Implementations of the [`RepositoryAccess`], [`RepositoryTransaction`] and
|
||||
/// [`Repository`] for the [`MapErr`] wrapper and [`Box<R>`]
|
||||
/// [`Repository`] for the [`crate::MapErr`] wrapper and [`Box<R>`]
|
||||
mod impls {
|
||||
use futures_util::{future::BoxFuture, FutureExt, TryFutureExt};
|
||||
|
||||
|
@ -26,7 +26,10 @@ pub struct MapErr<R, F> {
|
||||
}
|
||||
|
||||
impl<R, F> MapErr<R, F> {
|
||||
pub(crate) fn new(inner: R, mapper: F) -> Self {
|
||||
/// Create a new [`MapErr`] wrapper from an inner repository and a mapper
|
||||
/// function
|
||||
#[must_use]
|
||||
pub fn new(inner: R, mapper: F) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
mapper,
|
||||
|
Reference in New Issue
Block a user