Use util::BoxedFuture everywhere, for aesthetics

This commit is contained in:
Brian Picciano 2023-07-06 18:04:29 +02:00
parent 5e264093ec
commit 0b790ecc4a
3 changed files with 13 additions and 15 deletions

View File

@ -1,8 +1,8 @@
use std::{future, pin, sync, time};
use std::{sync, time};
use crate::domain::acme::{Certificate, PrivateKey};
use crate::domain::{self, acme};
use crate::domain::acme::{self, Certificate, PrivateKey};
use crate::error::unexpected::{self, Intoable, Mappable};
use crate::{domain, util};
const LETS_ENCRYPT_URL: &str = "https://acme-v02.api.letsencrypt.org/directory";
@ -14,7 +14,8 @@ pub trait Manager {
fn sync_domain<'mgr>(
&'mgr self,
domain: domain::Name,
) -> pin::Pin<Box<dyn future::Future<Output = Result<(), unexpected::Error>> + Send + 'mgr>>;
) -> util::BoxedFuture<'mgr, Result<(), unexpected::Error>>;
fn get_http01_challenge_key(&self, token: &str) -> Result<String, GetHttp01ChallengeKeyError>;
/// Returned vec is guaranteed to have len > 0
@ -86,8 +87,7 @@ impl Manager for ManagerImpl {
fn sync_domain<'mgr>(
&'mgr self,
domain: domain::Name,
) -> pin::Pin<Box<dyn future::Future<Output = Result<(), unexpected::Error>> + Send + 'mgr>>
{
) -> util::BoxedFuture<'mgr, Result<(), unexpected::Error>> {
Box::pin(async move {
// if there's an existing cert, and its expiry (determined by the soonest value of
// not_after amongst its parts) is later than 30 days from now, then we consider it to be

View File

@ -3,7 +3,7 @@ use crate::error::unexpected::{self, Mappable};
use crate::origin;
use crate::util;
use std::{future, pin, sync};
use std::sync;
use tokio_util::sync::CancellationToken;
#[derive(thiserror::Error, Debug)]
@ -146,13 +146,13 @@ pub trait Manager: Sync + Send + rustls::server::ResolvesServerCert {
fn sync_cert<'mgr>(
&'mgr self,
domain: domain::Name,
) -> pin::Pin<Box<dyn future::Future<Output = Result<(), unexpected::Error>> + Send + 'mgr>>;
) -> util::BoxedFuture<'mgr, Result<(), unexpected::Error>>;
fn sync_with_config<'mgr>(
&'mgr self,
domain: domain::Name,
config: config::Config,
) -> pin::Pin<Box<dyn future::Future<Output = Result<(), SyncWithConfigError>> + Send + 'mgr>>;
) -> util::BoxedFuture<'mgr, Result<(), SyncWithConfigError>>;
fn get_acme_http01_challenge_key(
&self,
@ -244,8 +244,7 @@ impl Manager for ManagerImpl {
fn sync_cert<'mgr>(
&'mgr self,
domain: domain::Name,
) -> pin::Pin<Box<dyn future::Future<Output = Result<(), unexpected::Error>> + Send + 'mgr>>
{
) -> util::BoxedFuture<'mgr, Result<(), unexpected::Error>> {
Box::pin(async move {
if let Some(ref acme_manager) = self.acme_manager {
acme_manager.sync_domain(domain.clone()).await?;
@ -259,8 +258,7 @@ impl Manager for ManagerImpl {
&'mgr self,
domain: domain::Name,
config: config::Config,
) -> pin::Pin<Box<dyn future::Future<Output = Result<(), SyncWithConfigError>> + Send + 'mgr>>
{
) -> util::BoxedFuture<'mgr, Result<(), SyncWithConfigError>> {
Box::pin(async move {
let config_hash = config
.hash()

View File

@ -12,13 +12,13 @@ pub fn open_file(path: &path::Path) -> io::Result<Option<fs::File>> {
}
}
type StaticFuture<O> = pin::Pin<Box<dyn futures::Future<Output = O> + Send + 'static>>;
pub type BoxedFuture<'a, O> = pin::Pin<Box<dyn futures::Future<Output = O> + Send + 'a>>;
pub struct TaskStack<E>
where
E: error::Error + Send + 'static,
{
wait_group: Vec<StaticFuture<Result<(), E>>>,
wait_group: Vec<BoxedFuture<'static, Result<(), E>>>,
}
impl<E> TaskStack<E>