Skip to content

Commit b02b3ad

Browse files
committed
units: Implement constructor for decoders
So the decoders can be used by downstream add constructors for them all. Also implement `Default` for the decoder types.
1 parent c6ce97e commit b02b3ad

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

units/src/amount/unsigned.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,17 @@ impl encoding::Encodable for Amount {
582582
#[cfg(feature = "encoding")]
583583
pub struct AmountDecoder(encoding::ArrayDecoder<8>);
584584

585+
#[cfg(feature = "encoding")]
586+
impl AmountDecoder {
587+
/// Constructs a new [`Amount`] decoder.
588+
pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
589+
}
590+
591+
#[cfg(feature = "encoding")]
592+
impl Default for AmountDecoder {
593+
fn default() -> Self { Self::new() }
594+
}
595+
585596
#[cfg(feature = "encoding")]
586597
impl encoding::Decoder for AmountDecoder {
587598
type Output = Amount;

units/src/block.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ impl encoding::Encodable for BlockHeight {
165165
#[cfg(feature = "encoding")]
166166
pub struct BlockHeightDecoder(encoding::ArrayDecoder<4>);
167167

168+
#[cfg(feature = "encoding")]
169+
impl Default for BlockHeightDecoder {
170+
fn default() -> Self { Self::new() }
171+
}
172+
173+
#[cfg(feature = "encoding")]
174+
impl BlockHeightDecoder {
175+
/// Constructs a new [`BlockHeight`] decoder.
176+
pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
177+
}
178+
168179
#[cfg(feature = "encoding")]
169180
impl encoding::Decoder for BlockHeightDecoder {
170181
type Output = BlockHeight;

units/src/locktime/absolute/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ impl encoding::Encodable for LockTime {
423423
#[cfg(feature = "encoding")]
424424
pub struct LockTimeDecoder(encoding::ArrayDecoder<4>);
425425

426+
#[cfg(feature = "encoding")]
427+
impl LockTimeDecoder {
428+
/// Constructs a new [`LockTime`] decoder.
429+
pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
430+
}
431+
432+
#[cfg(feature = "encoding")]
433+
impl Default for LockTimeDecoder {
434+
fn default() -> Self { Self::new() }
435+
}
436+
426437
#[cfg(feature = "encoding")]
427438
impl encoding::Decoder for LockTimeDecoder {
428439
type Output = LockTime;

units/src/sequence.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,17 @@ impl encoding::Encodable for Sequence {
288288
#[cfg(feature = "encoding")]
289289
pub struct SequenceDecoder(encoding::ArrayDecoder<4>);
290290

291+
#[cfg(feature = "encoding")]
292+
impl Default for SequenceDecoder {
293+
fn default() -> Self { Self::new() }
294+
}
295+
296+
#[cfg(feature = "encoding")]
297+
impl SequenceDecoder {
298+
/// Constructs a new [`Sequence`] decoder.
299+
pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
300+
}
301+
291302
#[cfg(feature = "encoding")]
292303
impl encoding::Decoder for SequenceDecoder {
293304
type Output = Sequence;

units/src/time.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ impl encoding::Encodable for BlockTime {
9898
#[cfg(feature = "encoding")]
9999
pub struct BlockTimeDecoder(encoding::ArrayDecoder<4>);
100100

101+
#[cfg(feature = "encoding")]
102+
impl Default for BlockTimeDecoder {
103+
fn default() -> Self { Self::new() }
104+
}
105+
106+
#[cfg(feature = "encoding")]
107+
impl BlockTimeDecoder {
108+
/// Constructs a new [`BlockTime`] decoder.
109+
pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
110+
}
111+
101112
#[cfg(feature = "encoding")]
102113
impl encoding::Decoder for BlockTimeDecoder {
103114
type Output = BlockTime;

0 commit comments

Comments
 (0)