Skip to content

Commit

Permalink
Merge rust-bitcoin#184: Add Default trait to Fe32 (derived)
Browse files Browse the repository at this point in the history
704e891 Add Default trait to Fe32 (derived) (optout)

Pull request description:

  See rust-bitcoin#187 .

  Add derived `Default` trait to `Fe32`, ~~and `ZERO` constant~~.
  Default is trivial to add, but it is useful in some cases.

ACKs for top commit:
  tcharding:
    ACK 704e891
  apoelstra:
    ACK 704e891
  clarkmoody:
    ACK 704e891

Tree-SHA512: 2d6385f92974d893c2e79d68712e85354ada8faa53ed30896e53f240a2e0272bc700c7559b531efeff22550ef6d58fc2ca5e4ed32df4ea4decd97c2b4f18d90f
  • Loading branch information
apoelstra committed Jul 31, 2024
2 parents 45bb227 + 704e891 commit 49ddb1c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/all-features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl core::convert::TryFrom<u16> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u32> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u64> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u8> for bech32::primitives::gf32::Fe32
impl core::default::Default for bech32::primitives::gf32::Fe32
impl core::error::Error for bech32::DecodeError
impl core::error::Error for bech32::EncodeError
impl core::error::Error for bech32::EncodeIoError
Expand Down Expand Up @@ -1009,6 +1010,7 @@ pub fn bech32::primitives::gf32::Fe32::add_assign(&mut self, other: &bech32::pri
pub fn bech32::primitives::gf32::Fe32::add_assign(&mut self, other: bech32::primitives::gf32::Fe32)
pub fn bech32::primitives::gf32::Fe32::as_ref(&self) -> &u8
pub fn bech32::primitives::gf32::Fe32::clone(&self) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::default() -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div(self, other: &bech32::primitives::gf32::Fe32) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div(self, other: bech32::primitives::gf32::Fe32) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div_assign(&mut self, other: &bech32::primitives::gf32::Fe32)
Expand Down
2 changes: 2 additions & 0 deletions api/alloc-only.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl core::convert::TryFrom<u16> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u32> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u64> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u8> for bech32::primitives::gf32::Fe32
impl core::default::Default for bech32::primitives::gf32::Fe32
impl core::fmt::Debug for bech32::DecodeError
impl core::fmt::Debug for bech32::EncodeError
impl core::fmt::Debug for bech32::primitives::checksum::PackedNull
Expand Down Expand Up @@ -961,6 +962,7 @@ pub fn bech32::primitives::gf32::Fe32::add_assign(&mut self, other: &bech32::pri
pub fn bech32::primitives::gf32::Fe32::add_assign(&mut self, other: bech32::primitives::gf32::Fe32)
pub fn bech32::primitives::gf32::Fe32::as_ref(&self) -> &u8
pub fn bech32::primitives::gf32::Fe32::clone(&self) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::default() -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div(self, other: &bech32::primitives::gf32::Fe32) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div(self, other: bech32::primitives::gf32::Fe32) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div_assign(&mut self, other: &bech32::primitives::gf32::Fe32)
Expand Down
2 changes: 2 additions & 0 deletions api/no-features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl core::convert::TryFrom<u16> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u32> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u64> for bech32::primitives::gf32::Fe32
impl core::convert::TryFrom<u8> for bech32::primitives::gf32::Fe32
impl core::default::Default for bech32::primitives::gf32::Fe32
impl core::fmt::Debug for bech32::EncodeError
impl core::fmt::Debug for bech32::primitives::checksum::PackedNull
impl core::fmt::Debug for bech32::primitives::decode::CharError
Expand Down Expand Up @@ -892,6 +893,7 @@ pub fn bech32::primitives::gf32::Fe32::add_assign(&mut self, other: &bech32::pri
pub fn bech32::primitives::gf32::Fe32::add_assign(&mut self, other: bech32::primitives::gf32::Fe32)
pub fn bech32::primitives::gf32::Fe32::as_ref(&self) -> &u8
pub fn bech32::primitives::gf32::Fe32::clone(&self) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::default() -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div(self, other: &bech32::primitives::gf32::Fe32) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div(self, other: bech32::primitives::gf32::Fe32) -> bech32::primitives::gf32::Fe32
pub fn bech32::primitives::gf32::Fe32::div_assign(&mut self, other: &bech32::primitives::gf32::Fe32)
Expand Down
8 changes: 7 additions & 1 deletion src/primitives/gf32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CHARS_INV: [i8; 128] = [
];

/// An element in GF(32), the finite field containing elements `[0,31]` inclusive.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct Fe32(pub(crate) u8);

Expand Down Expand Up @@ -487,6 +487,12 @@ mod tests {
assert_eq!(fe * Fe32::P, fe) // Fe32::P == Fe32(1)
}
}

#[test]
fn default() {
assert_eq!(Fe32::default().to_u8(), 0);
assert_eq!(Fe32::default(), Fe32::Q);
}
}

#[cfg(kani)]
Expand Down

0 comments on commit 49ddb1c

Please sign in to comment.