Skip to content

Commit 9f95b25

Browse files
committed
fix: refactors
1 parent ac803cb commit 9f95b25

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tracing = "0.1"
2121
tracing-subscriber = { version = "0.2", features = ["parking_lot"] }
2222
tracing-futures = { version = "0.2", features = ["futures-03"] }
2323
sqlx = { version = "0.5", default-features = false, features = ["runtime-tokio-rustls", "macros", "migrate"] }
24-
tokio = { version = "1.0", features = ["rt-multi-thread", "net", "signal", "macros", "test-util", "time"] }
24+
tokio = { version = "1.0", features = ["rt-multi-thread", "net", "signal", "macros", "time"] }
2525
tokio-stream = { version = "0.1", features = ["net"] }
2626
tokio-util = "0.6"
2727
tokio-rustls = "0.22"

src/api/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl MetricsConfig {
5454
}
5555
}
5656

57-
// type magic to return a closure which returns a unable warp filter
57+
// type magic to return a closure which returns a unnameable warp filter
5858
trait MetricsWrapper<I>: Fn(I) -> <Self as MetricsWrapper<I>>::Output
5959
where
6060
I: Filter<Extract = (WarpResponse, MetricsConfig), Error = Rejection> + Clone + Send + 'static,

src/api/proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(crate) fn wrap(
5454
}
5555
Ok(None) => {}
5656
Err(e) => {
57-
error!("Could net get remote.addr: {}", e);
57+
error!("Could net get remote.real: {}", e);
5858
}
5959
}
6060
Ok(conn)

src/api/tls.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
22
use futures_util::stream::{repeat, Stream};
33
use futures_util::{StreamExt, TryFutureExt, TryStreamExt};
44
use parking_lot::RwLock;
5-
use rustls::internal::pemfile::{certs, pkcs8_private_keys};
5+
use rustls::internal::pemfile::{certs, pkcs8_private_keys, rsa_private_keys};
66
use rustls::{NoClientAuth, ServerConfig};
77
use std::future::Future;
88
use std::sync::Arc;
@@ -45,7 +45,7 @@ where
4545
L: Stream<Item = IoResult<I>> + Send + 'static,
4646
I: Future<Output = IoResult<S>> + Send + 'static,
4747
S: AsyncRead + AsyncWrite + Send + Unpin + 'static,
48-
A: Fn() -> F + Clone + Send + 'static,
48+
A: FnOnce() -> F + Clone + Send + 'static,
4949
F: Future<Output = Result<TlsAcceptor>>,
5050
{
5151
listener
@@ -59,13 +59,13 @@ where
5959
}
6060

6161
// used for expressing a closure with an impl return
62-
trait Func: Fn() -> <Self as Func>::Output {
62+
trait Func: FnOnce() -> <Self as Func>::Output {
6363
type Output;
6464
}
6565

6666
impl<F, O> Func for F
6767
where
68-
F: Fn() -> O,
68+
F: FnOnce() -> O,
6969
{
7070
type Output = O;
7171
}
@@ -83,13 +83,9 @@ where
8383
let config = RwLock::new((None, Arc::new(server_config)));
8484
let wrapper = Arc::new((facade, config));
8585

86-
// workarround to make closure Fn instead of FnOnce
87-
move || {
88-
let wrapper = Arc::clone(&wrapper);
89-
async move {
90-
let (facade, config) = &*wrapper;
91-
load_cert(facade, config).await
92-
}
86+
|| async move {
87+
let (facade, config) = &*wrapper;
88+
load_cert(facade, config).await
9389
}
9490
}
9591

@@ -141,7 +137,7 @@ fn create_server_config(db_cert: &Cert) -> Result<Arc<ServerConfig>> {
141137
};
142138

143139
let mut privates =
144-
pkcs8_private_keys(&mut private.as_bytes()).map_err(|_| anyhow!("Private is invalid"))?;
140+
rsa_private_keys(&mut private.as_bytes()).map_err(|_| anyhow!("Private is invalid"))?;
145141
let private = privates
146142
.pop()
147143
.ok_or_else(|| anyhow!("Private Vec is empty"))?;

src/util.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Error;
2+
use std::fmt::{Debug, Display};
23
use std::io::{Error as IoError, ErrorKind};
34
use std::time::{SystemTime, UNIX_EPOCH};
45
use uuid::Uuid;
@@ -18,8 +19,18 @@ pub fn now() -> u64 {
1819
.as_secs()
1920
}
2021

21-
pub(crate) fn error<I: Into<Error>, E: From<IoError>>(err: I) -> E {
22+
pub(crate) fn error<I, E>(err: I) -> E
23+
where
24+
I: Into<Error>,
25+
E: From<IoError> + Display + Debug + Send + Sync + 'static,
26+
{
2227
let err = err.into();
28+
29+
let err = match err.downcast::<E>() {
30+
Ok(err) => return err,
31+
Err(err) => err,
32+
};
33+
2334
let err = match err.downcast::<IoError>() {
2435
Ok(err) => err,
2536
Err(err) => IoError::new(ErrorKind::Other, err),

0 commit comments

Comments
 (0)