Prefer implementing `From` over `Into`
authorElias Rohrer <dev@tnull.de>
Fri, 1 Mar 2024 10:42:54 +0000 (11:42 +0100)
committerElias Rohrer <dev@tnull.de>
Fri, 1 Mar 2024 10:42:54 +0000 (11:42 +0100)
.. as the std library docs state that implementing Into should be avoided:
"One should avoid implementing Into and implement From instead.
Implementing From automatically provides one with an implementation of
Into thanks to the blanket implementation in the standard library."

lightning/src/ln/mod.rs

index bf2e94caa03927184026a5ac4a1d7cfe3a3f6466..71b73390d1c80a9590afedecfbee6f542822a076 100644 (file)
@@ -112,9 +112,9 @@ impl core::fmt::Display for PaymentPreimage {
 }
 
 /// Converts a `PaymentPreimage` into a `PaymentHash` by hashing the preimage with SHA256.
-impl Into<PaymentHash> for PaymentPreimage {
-       fn into(self) -> PaymentHash {
-               PaymentHash(Sha256::hash(&self.0).to_byte_array())
+impl From<PaymentPreimage> for PaymentHash {
+       fn from(value: PaymentPreimage) -> Self {
+               PaymentHash(Sha256::hash(&value.0).to_byte_array())
        }
 }