Skip to content

Commit

Permalink
Remove unneeded allocation
Browse files Browse the repository at this point in the history
`<E as serde::de::Error>::custom()` accepts any `T: Display`, not just
`String`. Therefore it accepts `Arguments<'_>` too so we can use
`format_args!()` instead of `format!()`.

See lightningdevkit#2187 (comment)
  • Loading branch information
Kixunil authored and marctyndel committed Jun 15, 2023
1 parent 820b368 commit eda3281
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ impl<'de> Deserialize<'de> for Invoice {
fn deserialize<D>(deserializer: D) -> Result<Invoice, D::Error> where D: Deserializer<'de> {
let bolt11 = String::deserialize(deserializer)?
.parse::<Invoice>()
.map_err(|e| D::Error::custom(alloc::format!("{:?}", e)))?;
.map_err(|e| D::Error::custom(format_args!("{:?}", e)))?;

Ok(bolt11)
}
Expand Down

0 comments on commit eda3281

Please sign in to comment.