rustls_acme/caches/
boxed.rs

1use crate::{AccountCache, CertCache};
2use async_trait::async_trait;
3use std::fmt::Debug;
4
5pub struct BoxedErrCache<T: Send + Sync> {
6    inner: T,
7}
8
9impl<T: Send + Sync> BoxedErrCache<T> {
10    pub fn new(inner: T) -> Self {
11        Self { inner }
12    }
13    pub fn into_inner(self) -> T {
14        self.inner
15    }
16}
17
18fn box_err(e: impl Debug + 'static) -> Box<dyn Debug> {
19    Box::new(e)
20}
21
22#[async_trait]
23impl<T: CertCache> CertCache for BoxedErrCache<T>
24where
25    <T as CertCache>::EC: 'static,
26{
27    type EC = Box<dyn Debug>;
28    async fn load_cert(&self, domains: &[String], directory_url: &str) -> Result<Option<Vec<u8>>, Self::EC> {
29        self.inner.load_cert(domains, directory_url).await.map_err(box_err)
30    }
31
32    async fn store_cert(&self, domains: &[String], directory_url: &str, cert: &[u8]) -> Result<(), Self::EC> {
33        self.inner.store_cert(domains, directory_url, cert).await.map_err(box_err)
34    }
35}
36
37#[async_trait]
38impl<T: AccountCache> AccountCache for BoxedErrCache<T>
39where
40    <T as AccountCache>::EA: 'static,
41{
42    type EA = Box<dyn Debug>;
43    async fn load_account(&self, contact: &[String], directory_url: &str) -> Result<Option<Vec<u8>>, Self::EA> {
44        self.inner.load_account(contact, directory_url).await.map_err(box_err)
45    }
46
47    async fn store_account(&self, contact: &[String], directory_url: &str, account: &[u8]) -> Result<(), Self::EA> {
48        self.inner.store_account(contact, directory_url, account).await.map_err(box_err)
49    }
50}