Skip to content

Commit 6328823

Browse files
committed
refactor(client): don't allocate for ConnectError messages
1 parent 3a971c9 commit 6328823

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/client/legacy/connect/http.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -642,18 +642,17 @@ impl<R: Resolve> Future for HttpConnecting<R> {
642642

643643
// Not publicly exported (so missing_docs doesn't trigger).
644644
pub struct ConnectError {
645-
msg: Box<str>,
645+
msg: &'static str,
646646
cause: Option<Box<dyn StdError + Send + Sync>>,
647647
}
648648

649649
impl ConnectError {
650-
fn new<S, E>(msg: S, cause: E) -> ConnectError
650+
fn new<E>(msg: &'static str, cause: E) -> ConnectError
651651
where
652-
S: Into<Box<str>>,
653652
E: Into<Box<dyn StdError + Send + Sync>>,
654653
{
655654
ConnectError {
656-
msg: msg.into(),
655+
msg,
657656
cause: Some(cause.into()),
658657
}
659658
}
@@ -665,9 +664,8 @@ impl ConnectError {
665664
ConnectError::new("dns error", cause)
666665
}
667666

668-
fn m<S, E>(msg: S) -> impl FnOnce(E) -> ConnectError
667+
fn m<E>(msg: &'static str) -> impl FnOnce(E) -> ConnectError
669668
where
670-
S: Into<Box<str>>,
671669
E: Into<Box<dyn StdError + Send + Sync>>,
672670
{
673671
move |cause| ConnectError::new(msg, cause)
@@ -676,26 +674,18 @@ impl ConnectError {
676674

677675
impl fmt::Debug for ConnectError {
678676
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
677+
let mut b = f.debug_tuple("ConnectError");
678+
b.field(&self.msg);
679679
if let Some(ref cause) = self.cause {
680-
f.debug_tuple("ConnectError")
681-
.field(&self.msg)
682-
.field(cause)
683-
.finish()
684-
} else {
685-
self.msg.fmt(f)
680+
b.field(cause);
686681
}
682+
b.finish()
687683
}
688684
}
689685

690686
impl fmt::Display for ConnectError {
691687
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
692-
f.write_str(&self.msg)?;
693-
694-
if let Some(ref cause) = self.cause {
695-
write!(f, ": {cause}")?;
696-
}
697-
698-
Ok(())
688+
f.write_str(&self.msg)
699689
}
700690
}
701691

0 commit comments

Comments
 (0)