Skip to content

Commit f498576

Browse files
authored
Make JoinedAcceptor and AcmeAcceptor public (#1147)
1 parent fabdc75 commit f498576

File tree

23 files changed

+71
-67
lines changed

23 files changed

+71
-67
lines changed

crates/core/src/catcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn status_error_bytes(
317317
prefer_format.clone()
318318
};
319319
#[cfg(debug_assertions)]
320-
let cause = err.cause.as_ref().map(|e| format!("{:#?}", e));
320+
let cause = err.cause.as_ref().map(|e| format!("{e:#?}"));
321321
#[cfg(not(debug_assertions))]
322322
let cause: Option<&str> = None;
323323
#[cfg(debug_assertions)]

crates/core/src/conn/acme/listener.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ where
343343
});
344344
Ok(acceptor)
345345
}
346+
347+
/// Returns the config of this acceptor.
346348
pub fn server_config(&self) -> Arc<ServerConfig> {
347349
self.server_config.clone()
348350
}

crates/core/src/conn/acme/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ use parking_lot::RwLock;
7272
use serde::{Deserialize, Serialize};
7373

7474
use crate::http::StatusError;
75-
use crate::{async_trait, Depot, FlowCtrl, Handler, Request, Response};
75+
use crate::{Depot, FlowCtrl, Handler, Request, Response, async_trait};
7676
use cache::AcmeCache;
7777
pub use config::{AcmeConfig, AcmeConfigBuilder};
78-
pub use listener::AcmeListener;
78+
pub use listener::{AcmeAcceptor, AcmeListener};
7979
cfg_feature! {
8080
#![feature = "quinn"]
8181
pub use listener::AcmeQuinnListener;
@@ -154,7 +154,13 @@ pub(crate) struct Http01Handler {
154154

155155
#[async_trait]
156156
impl Handler for Http01Handler {
157-
async fn handle(&self, req: &mut Request, _depot: &mut Depot, res: &mut Response, _ctrl: &mut FlowCtrl) {
157+
async fn handle(
158+
&self,
159+
req: &mut Request,
160+
_depot: &mut Depot,
161+
res: &mut Response,
162+
_ctrl: &mut FlowCtrl,
163+
) {
158164
if let Some(token) = req.params().get("token") {
159165
let keys = self.keys.read();
160166
if let Some(value) = keys.get(token) {

crates/core/src/conn/joined.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ where
109109
}
110110
}
111111

112+
/// `JoinedAcceptor` is an acceptor that can accept connections from two different acceptors.
112113
pub struct JoinedAcceptor<A, B> {
113114
a: A,
114115
b: B,
115116
holdings: Vec<Holding>,
116117
}
117118

118119
impl<A, B> JoinedAcceptor<A, B> {
120+
/// Create a new `JoinedAcceptor`.
119121
pub fn new(a: A, b: B, holdings: Vec<Holding>) -> Self {
120122
JoinedAcceptor { a, b, holdings }
121123
}

crates/core/src/conn/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub mod tcp;
6161
pub use tcp::TcpListener;
6262

6363
mod joined;
64-
pub use joined::JoinedListener;
64+
pub use joined::{JoinedAcceptor, JoinedListener};
6565

6666
cfg_feature! {
6767
#![unix]

crates/core/src/conn/rustls/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ impl RustlsConfig {
267267
WebPkiClientVerifier::builder(read_trust_anchor(trust_anchor)?.into())
268268
.allow_unauthenticated()
269269
.build()
270-
.map_err(|e| IoError::other(format!("failed to build server config: {}", e)))?
270+
.map_err(|e| IoError::other(format!("failed to build server config: {e}")))?
271271
}
272272
TlsClientAuth::Required(trust_anchor) => {
273273
WebPkiClientVerifier::builder(read_trust_anchor(trust_anchor)?.into())
274274
.build()
275-
.map_err(|e| IoError::other(format!("failed to build server config: {}", e)))?
275+
.map_err(|e| IoError::other(format!("failed to build server config: {e}")))?
276276
}
277277
};
278278

crates/core/src/http/body/channel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl BodySender {
3030
pub(crate) fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<IoResult<()>> {
3131
self.data_tx
3232
.poll_ready(cx)
33-
.map_err(|e| IoError::other(format!("failed to poll ready: {}", e)))
33+
.map_err(|e| IoError::other(format!("failed to poll ready: {e}")))
3434
}
3535

3636
/// Returns whether this channel is closed without needing a context.
@@ -55,7 +55,7 @@ impl BodySender {
5555
self.ready().await?;
5656
self.data_tx
5757
.try_send(Ok(chunk.into()))
58-
.map_err(|e| IoError::other(format!("failed to send data: {}", e)))
58+
.map_err(|e| IoError::other(format!("failed to send data: {e}")))
5959
}
6060

6161
/// Send trailers on trailers channel.
@@ -92,11 +92,11 @@ impl futures_util::AsyncWrite for BodySender {
9292
self.data_tx
9393
.try_send(Ok(data))
9494
.map(|_| len)
95-
.map_err(|e| IoError::other(format!("failed to send data: {}", e))),
95+
.map_err(|e| IoError::other(format!("failed to send data: {e}"))),
9696
)
9797
}
9898
Poll::Ready(Err(e)) => {
99-
Poll::Ready(Err(IoError::other(format!("failed to poll ready: {}", e))))
99+
Poll::Ready(Err(IoError::other(format!("failed to poll ready: {e}"))))
100100
}
101101
Poll::Pending => Poll::Pending,
102102
}
@@ -129,11 +129,11 @@ impl tokio::io::AsyncWrite for BodySender {
129129
self.data_tx
130130
.try_send(Ok(data))
131131
.map(|_| len)
132-
.map_err(|e| IoError::other(format!("failed to send data: {}", e))),
132+
.map_err(|e| IoError::other(format!("failed to send data: {e}"))),
133133
)
134134
}
135135
Poll::Ready(Err(e)) => {
136-
Poll::Ready(Err(IoError::other(format!("failed to poll ready: {}", e))))
136+
Poll::Ready(Err(IoError::other(format!("failed to poll ready: {e}"))))
137137
}
138138
Poll::Pending => Poll::Pending,
139139
}

crates/core/src/http/errors/status_error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,25 +212,25 @@ impl Display for StatusError {
212212
self.code, self.name, self.brief
213213
);
214214
if let Some(detail) = &self.detail {
215-
write!(&mut str_error, " detail: {}", detail)?;
215+
write!(&mut str_error, " detail: {detail}")?;
216216
}
217217
if let Some(cause) = &self.cause {
218-
write!(&mut str_error, " cause: {}", cause)?;
218+
write!(&mut str_error, " cause: {cause}")?;
219219
}
220220
if let Some(origin) = &self.origin {
221221
let mut handle_cause = || {
222222
if let Some(e) = origin.downcast_ref::<&dyn StdError>() {
223-
return write!(&mut str_error, " origin: {}", e);
223+
return write!(&mut str_error, " origin: {e}");
224224
}
225225
if let Some(e) = origin.downcast_ref::<String>() {
226-
return write!(&mut str_error, " origin: {}", e);
226+
return write!(&mut str_error, " origin: {e}");
227227
}
228228
if let Some(e) = origin.downcast_ref::<&str>() {
229-
return write!(&mut str_error, " origin: {}", e);
229+
return write!(&mut str_error, " origin: {e}");
230230
}
231231
#[cfg(feature = "anyhow")]
232232
if let Some(e) = origin.downcast_ref::<anyhow::Error>() {
233-
return write!(&mut str_error, " origin: {}", e);
233+
return write!(&mut str_error, " origin: {e}");
234234
}
235235
write!(&mut str_error, " origin: <unknown error type>")
236236
};

crates/core/src/routing/filters/path.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl CombWisp {
388388
));
389389
}
390390
_ => {
391-
return Err(format!("unsupported wisp: {:?} add to CombWisp", wisp));
391+
return Err(format!("unsupported wisp: {wisp:?} add to CombWisp"));
392392
}
393393
}
394394
}
@@ -402,7 +402,7 @@ impl CombWisp {
402402
wild_regex,
403403
wild_start,
404404
})
405-
.map_err(|e| format!("Regex error: {}", e))
405+
.map_err(|e| format!("Regex error: {e}"))
406406
}
407407
}
408408
impl PathWisp for CombWisp {
@@ -438,7 +438,7 @@ impl PathWisp for CombWisp {
438438
if value.start() > start {
439439
matched_part.push_str(&picked[start..value.start()]);
440440
}
441-
matched_part.push_str(&format!("{{{}}}", name));
441+
matched_part.push_str(&format!("{{{name}}}"));
442442
start = value.end();
443443
}
444444
} else {
@@ -483,7 +483,7 @@ impl PathWisp for CombWisp {
483483
state.forward(cap.len());
484484
state.params.insert(wild_name, cap);
485485
#[cfg(feature = "matched-path")]
486-
state.matched_parts.push(format!("{{{}}}", wild_name));
486+
state.matched_parts.push(format!("{{{wild_name}}}"));
487487
true
488488
} else {
489489
false
@@ -551,18 +551,18 @@ impl RegexWisp {
551551
#[inline]
552552
fn new(name: String, regex: &str) -> Result<Self, String> {
553553
let regex = if !regex.starts_with('^') {
554-
&*format!("^{}", regex)
554+
&*format!("^{regex}")
555555
} else {
556556
regex
557557
};
558558
let regex = if !regex.ends_with('$') {
559-
&*format!("{}$", regex)
559+
&*format!("{regex}$")
560560
} else {
561561
regex
562562
};
563563
Ok(Self {
564564
name,
565-
regex: Regex::new(regex).map_err(|e| format!("invalid regex: `{}`, {}", regex, e))?,
565+
regex: Regex::new(regex).map_err(|e| format!("invalid regex: `{regex}`, {e}"))?,
566566
})
567567
}
568568
}
@@ -1035,7 +1035,7 @@ impl PathFilter {
10351035
let path_wisps = match parser.parse() {
10361036
Ok(path_wisps) => path_wisps,
10371037
Err(e) => {
1038-
panic!("{}, raw_value: {}", e, raw_value);
1038+
panic!("{e}, raw_value: {raw_value}");
10391039
}
10401040
};
10411041
PathFilter {

crates/core/src/serde/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl<'de> RequestDeserializer<'de> {
381381
return false;
382382
}
383383
_ => {
384-
panic!("unsupported source parser: {:?}", parser);
384+
panic!("unsupported source parser: {parser:?}");
385385
}
386386
}
387387
}

0 commit comments

Comments
 (0)