Merge rust-bitcoin/rust-bitcoin#2068: Fixes #2011: Customize Debug implementation of `absolute::LockTime`

71a5fe2b54 Customize Debug implementation of absolute::LockTime (Subhradeep Chakraborty)

Pull request description:

  Fixes https://github.com/rust-bitcoin/rust-bitcoin/issues/2011.

  This PR aims to make the "pretty print" of `absolute::LockTime` prettier by printing `X blocks` and `X seconds` for `Blocks` and `Seconds` respectively instead of the default Enum printing.

ACKs for top commit:
  apoelstra:
    ACK 71a5fe2b54
  tcharding:
    ACK 71a5fe2b54

Tree-SHA512: 79baad5ee0ba1aa892cb38588dae6a24977b8e42356208d6cc9adb007d1f8371e61dc82e35bb4dac9961216d68c56907f0db376c5c6fbb5a406728b8f7c3f5ad
This commit is contained in:
Andrew Poelstra 2023-09-21 16:55:57 +00:00
commit eda7e7df0d
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 12 additions and 1 deletions

View File

@ -67,7 +67,7 @@ pub const LOCK_TIME_THRESHOLD: u32 = 500_000_000;
/// };
/// ```
#[allow(clippy::derive_ord_xor_partial_ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub enum LockTime {
/// A block height lock time value.
///
@ -294,6 +294,17 @@ impl PartialOrd for LockTime {
}
}
impl fmt::Debug for LockTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use LockTime::*;
match *self {
Blocks(ref h) => write!(f, "{} blocks", h),
Seconds(ref t) => write!(f, "{} seconds", t),
}
}
}
impl fmt::Display for LockTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use LockTime::*;