Merge rust-bitcoin/rust-bitcoin#3726: units: Improve `Default`
a4a0f2921c
units: Add regression tests for Default impls (Tobin C. Harding)f5c2248a31
units: Derive Default for BlockInterval (Tobin C. Harding) Pull request description: Done while looking into [C-TOR](https://rust-lang.github.io/api-guidelines/predictability.html#c-ctor) - Derive `Default` for `BlockInterval` - Add regression test for all types that implement `Default` ACKs for top commit: apoelstra: ACK a4a0f2921cd2425fa46a8ade42f888d5268e6709; successfully ran local tests Tree-SHA512: ce39c2bcb37fc0fa70bd2553dd7843d9ac8f9528631706056ba89fda9623defadf32974091832b7a087121290b3f883bc8a8dcca070f1d90670eeee6b541de01
This commit is contained in:
commit
bfd35d49e3
|
@ -93,7 +93,7 @@ impl TryFrom<BlockHeight> for absolute::Height {
|
|||
///
|
||||
/// This type is not meant for constructing relative height based timelocks, this is a general
|
||||
/// purpose block interval abstraction. For locktimes please see [`locktime::relative::Height`].
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
// Public to try and make it really clear that there are no invariants.
|
||||
pub struct BlockInterval(pub u32);
|
||||
|
|
|
@ -98,12 +98,13 @@ struct CommonTraits {
|
|||
}
|
||||
|
||||
/// A struct that includes all types that implement `Default`.
|
||||
#[derive(Default)] // C-COMMON-TRAITS: `Default`
|
||||
#[derive(Debug, Default, PartialEq, Eq)] // C-COMMON-TRAITS: `Default`
|
||||
struct Default {
|
||||
a: Amount,
|
||||
b: SignedAmount,
|
||||
c: relative::Height,
|
||||
d: relative::Time,
|
||||
c: BlockInterval,
|
||||
d: relative::Height,
|
||||
e: relative::Time,
|
||||
}
|
||||
|
||||
/// A struct that includes all public error types.
|
||||
|
@ -249,3 +250,16 @@ fn test_sync() {
|
|||
assert_sync::<Types>();
|
||||
assert_sync::<Errors>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regression_default() {
|
||||
let got: Default = Default::default();
|
||||
let want = Default {
|
||||
a: Amount::ZERO,
|
||||
b: SignedAmount::ZERO,
|
||||
c: BlockInterval::ZERO,
|
||||
d: relative::Height::ZERO,
|
||||
e: relative::Time::ZERO,
|
||||
};
|
||||
assert_eq!(got, want);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue