Remove unneeded allocation
authorMartin Habovstiak <martin.habovstiak@gmail.com>
Thu, 4 May 2023 09:21:04 +0000 (11:21 +0200)
committerMartin Habovstiak <martin.habovstiak@gmail.com>
Thu, 4 May 2023 09:21:04 +0000 (11:21 +0200)
`<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 https://github.com/lightningdevkit/rust-lightning/pull/2187#discussion_r1168781355

lightning-invoice/src/lib.rs

index 101051b5e7f23509325d42301a424d3045fc7589..f53c8953b47c66b9344d86a928d9e834790989f7 100644 (file)
@@ -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)
        }