move conversion & rename & tidy

This commit is contained in:
stackinspector 2024-09-01 00:36:55 +08:00
parent 3245712ad3
commit 7bca27f76d
3 changed files with 11 additions and 12 deletions

View File

@ -4,6 +4,12 @@ use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::Client as HyperClient; use hyper_util::client::legacy::Client as HyperClient;
use hyper_util::{client::legacy::connect::HttpConnector, rt::TokioExecutor}; use hyper_util::{client::legacy::connect::HttpConnector, rt::TokioExecutor};
impl From<hyper_util::client::legacy::Error> for Error {
fn from(value: hyper_util::client::legacy::Error) -> Self {
Self::Other(Box::new(value))
}
}
struct DefaultClient(HyperClient<hyper_rustls::HttpsConnector<HttpConnector>, Full<Bytes>>); struct DefaultClient(HyperClient<hyper_rustls::HttpsConnector<HttpConnector>, Full<Bytes>>);
impl DefaultClient { impl DefaultClient {
@ -27,7 +33,7 @@ impl HttpClient for DefaultClient {
&self, &self,
req: Request<Full<Bytes>>, req: Request<Full<Bytes>>,
) -> Pin<Box<dyn Future<Output = Result<Response<Bytes>, Error>> + Send>> { ) -> Pin<Box<dyn Future<Output = Result<Response<Bytes>, Error>> + Send>> {
Box::pin(_response_future(self.0.request(req))) Box::pin(handle_response_future(self.0.request(req)))
} }
} }
@ -36,7 +42,7 @@ impl<C: Connect + Clone + Send + Sync + 'static> HttpClient for HyperClient<C, F
&self, &self,
req: Request<Full<Bytes>>, req: Request<Full<Bytes>>,
) -> Pin<Box<dyn Future<Output = Result<Response<Bytes>, Error>> + Send>> { ) -> Pin<Box<dyn Future<Output = Result<Response<Bytes>, Error>> + Send>> {
Box::pin(_response_future(self.request(req))) Box::pin(handle_response_future(self.request(req)))
} }
} }
@ -44,7 +50,7 @@ impl Account {
/// Restore an existing account from the given credentials /// Restore an existing account from the given credentials
/// ///
/// The [`AccountCredentials`] type is opaque, but supports deserialization. /// The [`AccountCredentials`] type is opaque, but supports deserialization.
pub async fn from_credentials(credentials: AccountCredentials) -> Result<Self, Error> { pub async fn from_credentials(credentials: AccountCredentials) -> Result<Self, Error> {
Ok(Self { Ok(Self {
inner: Arc::new( inner: Arc::new(
AccountInner::from_credentials(credentials, Box::new(DefaultClient::try_new()?)) AccountInner::from_credentials(credentials, Box::new(DefaultClient::try_new()?))
@ -57,7 +63,7 @@ impl Account {
/// ///
/// The returned [`AccountCredentials`] can be serialized and stored for later use. /// The returned [`AccountCredentials`] can be serialized and stored for later use.
/// Use [`Account::from_credentials()`] to restore the account from the credentials. /// Use [`Account::from_credentials()`] to restore the account from the credentials.
pub async fn create( pub async fn create(
account: &NewAccount<'_>, account: &NewAccount<'_>,
server_url: &str, server_url: &str,
external_account: Option<&ExternalAccountKey>, external_account: Option<&ExternalAccountKey>,

View File

@ -642,7 +642,7 @@ pub trait HttpClient: Send + Sync + 'static {
) -> Pin<Box<dyn Future<Output = Result<Response<Bytes>, Error>> + Send>>; ) -> Pin<Box<dyn Future<Output = Result<Response<Bytes>, Error>> + Send>>;
} }
async fn _response_future<B: http_body::Body<Error = impl Into<Error>>>( async fn handle_response_future<B: http_body::Body<Error = impl Into<Error>>>(
fut: impl Future<Output = Result<Response<B>, impl Into<Error>>>, fut: impl Future<Output = Result<Response<B>, impl Into<Error>>>,
) -> Result<Response<Bytes>, Error> { ) -> Result<Response<Bytes>, Error> {
match fut.await { match fut.await {

View File

@ -55,13 +55,6 @@ impl From<&'static str> for Error {
} }
} }
#[cfg(feature = "hyper-rustls")]
impl From<hyper_util::client::legacy::Error> for Error {
fn from(value: hyper_util::client::legacy::Error) -> Self {
Self::Other(Box::new(value))
}
}
/// ACME account credentials /// ACME account credentials
/// ///
/// This opaque type contains the account ID, the private key data and the /// This opaque type contains the account ID, the private key data and the