Skip to content

Commit

Permalink
Prefer implementing From over Into
Browse files Browse the repository at this point in the history
.. 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."
  • Loading branch information
tnull committed Mar 1, 2024
1 parent bf3bc42 commit fe50a50
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lightning/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit fe50a50

Please sign in to comment.