primitives: Convert various functions to const
What changed, and why it matters
This commit is a routine code-quality improvement. It marks a number of simple constructor and getter functions as 'const', which lets the Rust compiler evaluate them at compile time. There is no change to what the functions do, no bug fix, and no security-relevant behavior change.
No security action required. Treat as a normal library API enhancement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch converts zero-argument constructors (e.g., BlockHashDecoder::new, VersionDecoder::new, CompactTargetDecoder::new, ScriptBufDecoder::new, OutPointDecoder::new, TransactionDecoder::new, TxMerkleNodeDecoder::new, WitnessDecoder::new) and simple getter functions (Version::to_consensus, CompactTarget::to_consensus, Witness::len) from pub fn to pub const fn. The function bodies are unchanged. This is a pure API ergonomics/compile-time evaluation improvement with no runtime semantic change.
Changed components
primitives/src/block.rsprimitives/src/hash_types/block_hash.rsprimitives/src/hash_types/transaction_merkle_node.rsprimitives/src/pow.rsprimitives/src/script/owned.rsprimitives/src/transaction.rsprimitives/src/witness.rsInspect captured patch +44 / −44
diff --git a/api/primitives/all-features.txt b/api/primitives/all-features.txt
index 04d7c50b..2bcdc501 100644
--- a/api/primitives/all-features.txt
+++ b/api/primitives/all-features.txt
@@ -1231,7 +1231,12 @@ pub const fn bitcoin_primitives::WitnessMerkleNode::to_byte_array(self) -> [u8;
pub const fn bitcoin_primitives::Wtxid::as_byte_array(&self) -> &[u8; 32]
pub const fn bitcoin_primitives::Wtxid::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::Wtxid::to_byte_array(self) -> [u8; 32]
+pub const fn bitcoin_primitives::block::BlockHashDecoder::new() -> Self
pub const fn bitcoin_primitives::block::Version::from_consensus(v: i32) -> Self
+pub const fn bitcoin_primitives::block::Version::to_consensus(self) -> i32
+pub const fn bitcoin_primitives::block::VersionDecoder::new() -> Self
+pub const fn bitcoin_primitives::pow::CompactTarget::to_consensus(self) -> u32
+pub const fn bitcoin_primitives::pow::CompactTargetDecoder::new() -> Self
pub const fn bitcoin_primitives::script::Script<T>::as_bytes(&self) -> &[u8]
pub const fn bitcoin_primitives::script::Script<T>::from_bytes(bytes: &[u8]) -> &Self
pub const fn bitcoin_primitives::script::Script<T>::is_empty(&self) -> bool
@@ -1239,16 +1244,23 @@ pub const fn bitcoin_primitives::script::Script<T>::len(&self) -> usize
pub const fn bitcoin_primitives::script::Script<T>::new() -> &'static Self
pub const fn bitcoin_primitives::script::ScriptBuf<T>::from_bytes(bytes: alloc::vec::Vec<u8>) -> Self
pub const fn bitcoin_primitives::script::ScriptBuf<T>::new() -> Self
+pub const fn bitcoin_primitives::script::ScriptBufDecoder<T>::new() -> Self
pub const fn bitcoin_primitives::script::ScriptHash::as_byte_array(&self) -> &[u8; 20]
pub const fn bitcoin_primitives::script::ScriptHash::from_byte_array(bytes: [u8; 20]) -> Self
pub const fn bitcoin_primitives::script::ScriptHash::to_byte_array(self) -> [u8; 20]
pub const fn bitcoin_primitives::script::WScriptHash::as_byte_array(&self) -> &[u8; 32]
pub const fn bitcoin_primitives::script::WScriptHash::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::script::WScriptHash::to_byte_array(self) -> [u8; 32]
+pub const fn bitcoin_primitives::transaction::OutPointDecoder::new() -> Self
+pub const fn bitcoin_primitives::transaction::TransactionDecoder::new() -> Self
+pub const fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::new() -> Self
pub const fn bitcoin_primitives::transaction::Version::is_standard(self) -> bool
pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> Self
pub const fn bitcoin_primitives::transaction::Version::to_u32(self) -> u32
+pub const fn bitcoin_primitives::transaction::VersionDecoder::new() -> Self
+pub const fn bitcoin_primitives::witness::Witness::len(&self) -> usize
pub const fn bitcoin_primitives::witness::Witness::new() -> Self
+pub const fn bitcoin_primitives::witness::WitnessDecoder::new() -> Self
pub enum bitcoin_primitives::BlockChecked
pub enum bitcoin_primitives::BlockUnchecked
pub enum bitcoin_primitives::block::Checked
@@ -1414,7 +1426,6 @@ pub fn bitcoin_primitives::block::BlockEncoder<'e>::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::BlockEncoder<'e>::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::block::BlockHashDecoder::default() -> Self
pub fn bitcoin_primitives::block::BlockHashDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::block::BlockHashDecoder::new() -> Self
pub fn bitcoin_primitives::block::BlockHashDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::block::BlockHashDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::BlockHashDecoderError::clone(&self) -> bitcoin_primitives::block::BlockHashDecoderError
@@ -1470,10 +1481,8 @@ pub fn bitcoin_primitives::block::Version::hash<__H: core::hash::Hasher>(&self,
pub fn bitcoin_primitives::block::Version::is_signalling_soft_fork(self, bit: u8) -> bool
pub fn bitcoin_primitives::block::Version::partial_cmp(&self, other: &bitcoin_primitives::block::Version) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::block::Version::serialize<__S>(&self, __serializer: __S) -> core::result::Result<<__S as serde::ser::Serializer>::Ok, <__S as serde::ser::Serializer>::Error> where __S: serde::ser::Serializer
-pub fn bitcoin_primitives::block::Version::to_consensus(self) -> i32
pub fn bitcoin_primitives::block::VersionDecoder::default() -> Self
pub fn bitcoin_primitives::block::VersionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::block::VersionDecoder::new() -> Self
pub fn bitcoin_primitives::block::VersionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::block::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::VersionDecoderError::clone(&self) -> bitcoin_primitives::block::VersionDecoderError
@@ -1497,11 +1506,9 @@ pub fn bitcoin_primitives::pow::CompactTarget::from_consensus(bits: u32) -> Self
pub fn bitcoin_primitives::pow::CompactTarget::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::pow::CompactTarget::partial_cmp(&self, other: &bitcoin_primitives::pow::CompactTarget) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::pow::CompactTarget::serialize<__S>(&self, __serializer: __S) -> core::result::Result<<__S as serde::ser::Serializer>::Ok, <__S as serde::ser::Serializer>::Error> where __S: serde::ser::Serializer
-pub fn bitcoin_primitives::pow::CompactTarget::to_consensus(self) -> u32
pub fn bitcoin_primitives::pow::CompactTarget::to_hex(self) -> alloc::string::String
pub fn bitcoin_primitives::pow::CompactTargetDecoder::default() -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::pow::CompactTargetDecoder::new() -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::pow::CompactTargetDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::clone(&self) -> bitcoin_primitives::pow::CompactTargetDecoderError
@@ -1584,7 +1591,6 @@ pub fn bitcoin_primitives::script::ScriptBuf<T>::to_hex(&self) -> alloc::string:
pub fn bitcoin_primitives::script::ScriptBuf<T>::with_capacity(capacity: usize) -> Self
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::default() -> Self
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::new() -> Self
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::read_limit(&self) -> usize
pub fn bitcoin_primitives::script::ScriptBufDecoderError::clone(&self) -> bitcoin_primitives::script::ScriptBufDecoderError
@@ -1672,7 +1678,6 @@ pub fn bitcoin_primitives::transaction::OutPoint::partial_cmp(&self, other: &bit
pub fn bitcoin_primitives::transaction::OutPoint::serialize<S>(&self, serializer: S) -> core::result::Result<<S as serde::ser::Serializer>::Ok, <S as serde::ser::Serializer>::Error> where S: serde::ser::Serializer
pub fn bitcoin_primitives::transaction::OutPointDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::OutPointDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::OutPointDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::OutPointDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::OutPointDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::OutPointDecoderError::clone(&self) -> bitcoin_primitives::transaction::OutPointDecoderError
@@ -1700,7 +1705,6 @@ pub fn bitcoin_primitives::transaction::Transaction::hash<__H: core::hash::Hashe
pub fn bitcoin_primitives::transaction::Transaction::partial_cmp(&self, other: &Self) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::TransactionDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::TransactionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::TransactionDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::TransactionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::TransactionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::TransactionDecoderError::clone(&self) -> bitcoin_primitives::transaction::TransactionDecoderError
@@ -1736,7 +1740,6 @@ pub fn bitcoin_primitives::transaction::TxInEncoder<'e>::advance(&mut self) -> b
pub fn bitcoin_primitives::transaction::TxInEncoder<'e>::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::clone(&self) -> bitcoin_primitives::transaction::TxMerkleNodeDecoderError
@@ -1777,7 +1780,6 @@ pub fn bitcoin_primitives::transaction::Version::partial_cmp(&self, other: &bitc
pub fn bitcoin_primitives::transaction::Version::serialize<__S>(&self, __serializer: __S) -> core::result::Result<<__S as serde::ser::Serializer>::Ok, <__S as serde::ser::Serializer>::Error> where __S: serde::ser::Serializer
pub fn bitcoin_primitives::transaction::VersionDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::VersionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::VersionDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::VersionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::VersionDecoderError::clone(&self) -> bitcoin_primitives::transaction::VersionDecoderError
@@ -1836,7 +1838,6 @@ pub fn bitcoin_primitives::witness::Witness::index(&self, index: usize) -> &Self
pub fn bitcoin_primitives::witness::Witness::is_empty(&self) -> bool
pub fn bitcoin_primitives::witness::Witness::iter(&self) -> bitcoin_primitives::witness::Iter<'_>
pub fn bitcoin_primitives::witness::Witness::last(&self) -> core::option::Option<&[u8]>
-pub fn bitcoin_primitives::witness::Witness::len(&self) -> usize
pub fn bitcoin_primitives::witness::Witness::partial_cmp(&self, other: &bitcoin_primitives::witness::Witness) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::witness::Witness::push<T: core::convert::AsRef<[u8]>>(&mut self, new_element: T)
pub fn bitcoin_primitives::witness::Witness::serialize<S>(&self, serializer: S) -> core::result::Result<<S as serde::ser::Serializer>::Ok, <S as serde::ser::Serializer>::Error> where S: serde::ser::Serializer
@@ -1844,7 +1845,6 @@ pub fn bitcoin_primitives::witness::Witness::size(&self) -> usize
pub fn bitcoin_primitives::witness::Witness::to_vec(&self) -> alloc::vec::Vec<alloc::vec::Vec<u8>>
pub fn bitcoin_primitives::witness::WitnessDecoder::default() -> Self
pub fn bitcoin_primitives::witness::WitnessDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::witness::WitnessDecoder::new() -> Self
pub fn bitcoin_primitives::witness::WitnessDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::witness::WitnessDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::witness::WitnessDecoderError::clone(&self) -> bitcoin_primitives::witness::WitnessDecoderError
diff --git a/api/primitives/alloc-only.txt b/api/primitives/alloc-only.txt
index bd56264d..15134fcc 100644
--- a/api/primitives/alloc-only.txt
+++ b/api/primitives/alloc-only.txt
@@ -1100,7 +1100,12 @@ pub const fn bitcoin_primitives::WitnessMerkleNode::to_byte_array(self) -> [u8;
pub const fn bitcoin_primitives::Wtxid::as_byte_array(&self) -> &[u8; 32]
pub const fn bitcoin_primitives::Wtxid::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::Wtxid::to_byte_array(self) -> [u8; 32]
+pub const fn bitcoin_primitives::block::BlockHashDecoder::new() -> Self
pub const fn bitcoin_primitives::block::Version::from_consensus(v: i32) -> Self
+pub const fn bitcoin_primitives::block::Version::to_consensus(self) -> i32
+pub const fn bitcoin_primitives::block::VersionDecoder::new() -> Self
+pub const fn bitcoin_primitives::pow::CompactTarget::to_consensus(self) -> u32
+pub const fn bitcoin_primitives::pow::CompactTargetDecoder::new() -> Self
pub const fn bitcoin_primitives::script::Script<T>::as_bytes(&self) -> &[u8]
pub const fn bitcoin_primitives::script::Script<T>::from_bytes(bytes: &[u8]) -> &Self
pub const fn bitcoin_primitives::script::Script<T>::is_empty(&self) -> bool
@@ -1108,16 +1113,23 @@ pub const fn bitcoin_primitives::script::Script<T>::len(&self) -> usize
pub const fn bitcoin_primitives::script::Script<T>::new() -> &'static Self
pub const fn bitcoin_primitives::script::ScriptBuf<T>::from_bytes(bytes: alloc::vec::Vec<u8>) -> Self
pub const fn bitcoin_primitives::script::ScriptBuf<T>::new() -> Self
+pub const fn bitcoin_primitives::script::ScriptBufDecoder<T>::new() -> Self
pub const fn bitcoin_primitives::script::ScriptHash::as_byte_array(&self) -> &[u8; 20]
pub const fn bitcoin_primitives::script::ScriptHash::from_byte_array(bytes: [u8; 20]) -> Self
pub const fn bitcoin_primitives::script::ScriptHash::to_byte_array(self) -> [u8; 20]
pub const fn bitcoin_primitives::script::WScriptHash::as_byte_array(&self) -> &[u8; 32]
pub const fn bitcoin_primitives::script::WScriptHash::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::script::WScriptHash::to_byte_array(self) -> [u8; 32]
+pub const fn bitcoin_primitives::transaction::OutPointDecoder::new() -> Self
+pub const fn bitcoin_primitives::transaction::TransactionDecoder::new() -> Self
+pub const fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::new() -> Self
pub const fn bitcoin_primitives::transaction::Version::is_standard(self) -> bool
pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> Self
pub const fn bitcoin_primitives::transaction::Version::to_u32(self) -> u32
+pub const fn bitcoin_primitives::transaction::VersionDecoder::new() -> Self
+pub const fn bitcoin_primitives::witness::Witness::len(&self) -> usize
pub const fn bitcoin_primitives::witness::Witness::new() -> Self
+pub const fn bitcoin_primitives::witness::WitnessDecoder::new() -> Self
pub enum bitcoin_primitives::BlockChecked
pub enum bitcoin_primitives::BlockUnchecked
pub enum bitcoin_primitives::block::Checked
@@ -1250,7 +1262,6 @@ pub fn bitcoin_primitives::block::BlockEncoder<'e>::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::BlockEncoder<'e>::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::block::BlockHashDecoder::default() -> Self
pub fn bitcoin_primitives::block::BlockHashDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::block::BlockHashDecoder::new() -> Self
pub fn bitcoin_primitives::block::BlockHashDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::block::BlockHashDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::BlockHashDecoderError::clone(&self) -> bitcoin_primitives::block::BlockHashDecoderError
@@ -1300,10 +1311,8 @@ pub fn bitcoin_primitives::block::Version::fmt(&self, f: &mut core::fmt::Formatt
pub fn bitcoin_primitives::block::Version::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::block::Version::is_signalling_soft_fork(self, bit: u8) -> bool
pub fn bitcoin_primitives::block::Version::partial_cmp(&self, other: &bitcoin_primitives::block::Version) -> core::option::Option<core::cmp::Ordering>
-pub fn bitcoin_primitives::block::Version::to_consensus(self) -> i32
pub fn bitcoin_primitives::block::VersionDecoder::default() -> Self
pub fn bitcoin_primitives::block::VersionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::block::VersionDecoder::new() -> Self
pub fn bitcoin_primitives::block::VersionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::block::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::VersionDecoderError::clone(&self) -> bitcoin_primitives::block::VersionDecoderError
@@ -1324,11 +1333,9 @@ pub fn bitcoin_primitives::pow::CompactTarget::fmt(&self, f: &mut core::fmt::For
pub fn bitcoin_primitives::pow::CompactTarget::from_consensus(bits: u32) -> Self
pub fn bitcoin_primitives::pow::CompactTarget::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::pow::CompactTarget::partial_cmp(&self, other: &bitcoin_primitives::pow::CompactTarget) -> core::option::Option<core::cmp::Ordering>
-pub fn bitcoin_primitives::pow::CompactTarget::to_consensus(self) -> u32
pub fn bitcoin_primitives::pow::CompactTarget::to_hex(self) -> alloc::string::String
pub fn bitcoin_primitives::pow::CompactTargetDecoder::default() -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::pow::CompactTargetDecoder::new() -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::pow::CompactTargetDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::clone(&self) -> bitcoin_primitives::pow::CompactTargetDecoderError
@@ -1404,7 +1411,6 @@ pub fn bitcoin_primitives::script::ScriptBuf<T>::reserve_exact(&mut self, additi
pub fn bitcoin_primitives::script::ScriptBuf<T>::with_capacity(capacity: usize) -> Self
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::default() -> Self
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::new() -> Self
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::script::ScriptBufDecoder<T>::read_limit(&self) -> usize
pub fn bitcoin_primitives::script::ScriptBufDecoderError::clone(&self) -> bitcoin_primitives::script::ScriptBufDecoderError
@@ -1479,7 +1485,6 @@ pub fn bitcoin_primitives::transaction::OutPoint::hash<__H: core::hash::Hasher>(
pub fn bitcoin_primitives::transaction::OutPoint::partial_cmp(&self, other: &bitcoin_primitives::transaction::OutPoint) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::OutPointDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::OutPointDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::OutPointDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::OutPointDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::OutPointDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::OutPointDecoderError::clone(&self) -> bitcoin_primitives::transaction::OutPointDecoderError
@@ -1500,7 +1505,6 @@ pub fn bitcoin_primitives::transaction::Transaction::hash<__H: core::hash::Hashe
pub fn bitcoin_primitives::transaction::Transaction::partial_cmp(&self, other: &Self) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::TransactionDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::TransactionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::TransactionDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::TransactionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::TransactionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::TransactionDecoderError::clone(&self) -> bitcoin_primitives::transaction::TransactionDecoderError
@@ -1533,7 +1537,6 @@ pub fn bitcoin_primitives::transaction::TxInEncoder<'e>::advance(&mut self) -> b
pub fn bitcoin_primitives::transaction::TxInEncoder<'e>::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::clone(&self) -> bitcoin_primitives::transaction::TxMerkleNodeDecoderError
@@ -1568,7 +1571,6 @@ pub fn bitcoin_primitives::transaction::Version::hash<__H: core::hash::Hasher>(&
pub fn bitcoin_primitives::transaction::Version::partial_cmp(&self, other: &bitcoin_primitives::transaction::Version) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::VersionDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::VersionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::VersionDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::VersionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::VersionDecoderError::clone(&self) -> bitcoin_primitives::transaction::VersionDecoderError
@@ -1623,14 +1625,12 @@ pub fn bitcoin_primitives::witness::Witness::index(&self, index: usize) -> &Self
pub fn bitcoin_primitives::witness::Witness::is_empty(&self) -> bool
pub fn bitcoin_primitives::witness::Witness::iter(&self) -> bitcoin_primitives::witness::Iter<'_>
pub fn bitcoin_primitives::witness::Witness::last(&self) -> core::option::Option<&[u8]>
-pub fn bitcoin_primitives::witness::Witness::len(&self) -> usize
pub fn bitcoin_primitives::witness::Witness::partial_cmp(&self, other: &bitcoin_primitives::witness::Witness) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::witness::Witness::push<T: core::convert::AsRef<[u8]>>(&mut self, new_element: T)
pub fn bitcoin_primitives::witness::Witness::size(&self) -> usize
pub fn bitcoin_primitives::witness::Witness::to_vec(&self) -> alloc::vec::Vec<alloc::vec::Vec<u8>>
pub fn bitcoin_primitives::witness::WitnessDecoder::default() -> Self
pub fn bitcoin_primitives::witness::WitnessDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::witness::WitnessDecoder::new() -> Self
pub fn bitcoin_primitives::witness::WitnessDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::witness::WitnessDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::witness::WitnessDecoderError::clone(&self) -> bitcoin_primitives::witness::WitnessDecoderError
diff --git a/api/primitives/no-features.txt b/api/primitives/no-features.txt
index a85df9ae..bdbecb94 100644
--- a/api/primitives/no-features.txt
+++ b/api/primitives/no-features.txt
@@ -472,10 +472,18 @@ pub const fn bitcoin_primitives::WitnessMerkleNode::to_byte_array(self) -> [u8;
pub const fn bitcoin_primitives::Wtxid::as_byte_array(&self) -> &[u8; 32]
pub const fn bitcoin_primitives::Wtxid::from_byte_array(bytes: [u8; 32]) -> Self
pub const fn bitcoin_primitives::Wtxid::to_byte_array(self) -> [u8; 32]
+pub const fn bitcoin_primitives::block::BlockHashDecoder::new() -> Self
pub const fn bitcoin_primitives::block::Version::from_consensus(v: i32) -> Self
+pub const fn bitcoin_primitives::block::Version::to_consensus(self) -> i32
+pub const fn bitcoin_primitives::block::VersionDecoder::new() -> Self
+pub const fn bitcoin_primitives::pow::CompactTarget::to_consensus(self) -> u32
+pub const fn bitcoin_primitives::pow::CompactTargetDecoder::new() -> Self
+pub const fn bitcoin_primitives::transaction::OutPointDecoder::new() -> Self
+pub const fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::new() -> Self
pub const fn bitcoin_primitives::transaction::Version::is_standard(self) -> bool
pub const fn bitcoin_primitives::transaction::Version::maybe_non_standard(version: u32) -> Self
pub const fn bitcoin_primitives::transaction::Version::to_u32(self) -> u32
+pub const fn bitcoin_primitives::transaction::VersionDecoder::new() -> Self
pub fn bitcoin_primitives::BlockHash::as_ref(&self) -> &[u8; 32]
pub fn bitcoin_primitives::BlockHash::as_ref(&self) -> &[u8]
pub fn bitcoin_primitives::BlockHash::borrow(&self) -> &[u8; 32]
@@ -554,7 +562,6 @@ pub fn bitcoin_primitives::Wtxid::hash<__H: core::hash::Hasher>(&self, state: &m
pub fn bitcoin_primitives::Wtxid::partial_cmp(&self, other: &bitcoin_primitives::Wtxid) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::block::BlockHashDecoder::default() -> Self
pub fn bitcoin_primitives::block::BlockHashDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::block::BlockHashDecoder::new() -> Self
pub fn bitcoin_primitives::block::BlockHashDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::block::BlockHashDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::BlockHashDecoderError::clone(&self) -> bitcoin_primitives::block::BlockHashDecoderError
@@ -584,10 +591,8 @@ pub fn bitcoin_primitives::block::Version::fmt(&self, f: &mut core::fmt::Formatt
pub fn bitcoin_primitives::block::Version::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::block::Version::is_signalling_soft_fork(self, bit: u8) -> bool
pub fn bitcoin_primitives::block::Version::partial_cmp(&self, other: &bitcoin_primitives::block::Version) -> core::option::Option<core::cmp::Ordering>
-pub fn bitcoin_primitives::block::Version::to_consensus(self) -> i32
pub fn bitcoin_primitives::block::VersionDecoder::default() -> Self
pub fn bitcoin_primitives::block::VersionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::block::VersionDecoder::new() -> Self
pub fn bitcoin_primitives::block::VersionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::block::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::VersionDecoderError::clone(&self) -> bitcoin_primitives::block::VersionDecoderError
@@ -608,10 +613,8 @@ pub fn bitcoin_primitives::pow::CompactTarget::fmt(&self, f: &mut core::fmt::For
pub fn bitcoin_primitives::pow::CompactTarget::from_consensus(bits: u32) -> Self
pub fn bitcoin_primitives::pow::CompactTarget::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
pub fn bitcoin_primitives::pow::CompactTarget::partial_cmp(&self, other: &bitcoin_primitives::pow::CompactTarget) -> core::option::Option<core::cmp::Ordering>
-pub fn bitcoin_primitives::pow::CompactTarget::to_consensus(self) -> u32
pub fn bitcoin_primitives::pow::CompactTargetDecoder::default() -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::pow::CompactTargetDecoder::new() -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::pow::CompactTargetDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::clone(&self) -> bitcoin_primitives::pow::CompactTargetDecoderError
@@ -631,7 +634,6 @@ pub fn bitcoin_primitives::transaction::OutPoint::hash<__H: core::hash::Hasher>(
pub fn bitcoin_primitives::transaction::OutPoint::partial_cmp(&self, other: &bitcoin_primitives::transaction::OutPoint) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::OutPointDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::OutPointDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::OutPointDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::OutPointDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::OutPointDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::OutPointDecoderError::clone(&self) -> bitcoin_primitives::transaction::OutPointDecoderError
@@ -641,7 +643,6 @@ pub fn bitcoin_primitives::transaction::OutPointEncoder<'e>::advance(&mut self)
pub fn bitcoin_primitives::transaction::OutPointEncoder<'e>::current_chunk(&self) -> &[u8]
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::clone(&self) -> bitcoin_primitives::transaction::TxMerkleNodeDecoderError
@@ -659,7 +660,6 @@ pub fn bitcoin_primitives::transaction::Version::hash<__H: core::hash::Hasher>(&
pub fn bitcoin_primitives::transaction::Version::partial_cmp(&self, other: &bitcoin_primitives::transaction::Version) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::VersionDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::VersionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
-pub fn bitcoin_primitives::transaction::VersionDecoder::new() -> Self
pub fn bitcoin_primitives::transaction::VersionDecoder::push_bytes(&mut self, bytes: &mut &[u8]) -> core::result::Result<bool, Self::Error>
pub fn bitcoin_primitives::transaction::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::transaction::VersionDecoderError::clone(&self) -> bitcoin_primitives::transaction::VersionDecoderError
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index 3561e00d..09c30c18 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -549,7 +549,7 @@ impl Version {
///
/// This is the data type used in consensus code in Bitcoin Core.
#[inline]
- pub fn to_consensus(self) -> i32 { self.0 }
+ pub const fn to_consensus(self) -> i32 { self.0 }
/// Checks whether the version number is signalling a soft fork at the given bit.
///
@@ -595,7 +595,7 @@ pub struct VersionDecoder(encoding::ArrayDecoder<4>);
impl VersionDecoder {
/// Constructs a new [`Version`] decoder.
- pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
+ pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for VersionDecoder {
diff --git a/primitives/src/hash_types/block_hash.rs b/primitives/src/hash_types/block_hash.rs
index 0c6ad61c..ea0e35c0 100644
--- a/primitives/src/hash_types/block_hash.rs
+++ b/primitives/src/hash_types/block_hash.rs
@@ -46,7 +46,7 @@ pub struct BlockHashDecoder(encoding::ArrayDecoder<32>);
impl BlockHashDecoder {
/// Constructs a new [`BlockHash`] decoder.
- pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
+ pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for BlockHashDecoder {
diff --git a/primitives/src/hash_types/transaction_merkle_node.rs b/primitives/src/hash_types/transaction_merkle_node.rs
index a2aa1e02..3f9d03e9 100644
--- a/primitives/src/hash_types/transaction_merkle_node.rs
+++ b/primitives/src/hash_types/transaction_merkle_node.rs
@@ -40,7 +40,7 @@ pub struct TxMerkleNodeDecoder(encoding::ArrayDecoder<32>);
impl TxMerkleNodeDecoder {
/// Constructs a new [`TxMerkleNode`] decoder.
- pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
+ pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for TxMerkleNodeDecoder {
diff --git a/primitives/src/pow.rs b/primitives/src/pow.rs
index 63aec1b5..1e2eb9ad 100644
--- a/primitives/src/pow.rs
+++ b/primitives/src/pow.rs
@@ -32,7 +32,7 @@ impl CompactTarget {
/// Returns the consensus encoded `u32` representation of this [`CompactTarget`].
#[inline]
- pub fn to_consensus(self) -> u32 { self.0 }
+ pub const fn to_consensus(self) -> u32 { self.0 }
/// Gets the hex representation of this [`CompactTarget`].
#[cfg(feature = "alloc")]
@@ -70,7 +70,7 @@ pub struct CompactTargetDecoder(encoding::ArrayDecoder<4>);
impl CompactTargetDecoder {
/// Constructs a new [`CompactTarget`] decoder.
- pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
+ pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for CompactTargetDecoder {
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index 463b4711..64a239a0 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -155,7 +155,7 @@ pub struct ScriptBufDecoder<T>(ByteVecDecoder, PhantomData<T>);
impl<T> ScriptBufDecoder<T> {
/// Constructs a new [`ScriptBuf`] decoder.
- pub fn new() -> Self { Self(ByteVecDecoder::new(), PhantomData) }
+ pub const fn new() -> Self { Self(ByteVecDecoder::new(), PhantomData) }
}
impl<T> Default for ScriptBufDecoder<T> {
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index d7312e99..98a16999 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -365,7 +365,7 @@ pub struct TransactionDecoder {
#[cfg(feature = "alloc")]
impl TransactionDecoder {
/// Constructs a new [`TransactionDecoder`].
- pub fn new() -> Self { Self { state: TransactionDecoderState::Version(VersionDecoder::new()) } }
+ pub const fn new() -> Self { Self { state: TransactionDecoderState::Version(VersionDecoder::new()) } }
}
#[cfg(feature = "alloc")]
@@ -1085,7 +1085,7 @@ pub struct OutPointDecoder(encoding::ArrayDecoder<36>);
impl OutPointDecoder {
/// Constructs a new [`OutPoint`] decoder.
- pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
+ pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for OutPointDecoder {
@@ -1374,7 +1374,7 @@ pub struct VersionDecoder(encoding::ArrayDecoder<4>);
impl VersionDecoder {
/// Constructs a new [`Version`] decoder.
- pub fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
+ pub const fn new() -> Self { Self(encoding::ArrayDecoder::new()) }
}
impl Default for VersionDecoder {
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index e3dacc81..ab7c0917 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -128,7 +128,7 @@ impl Witness {
/// Returns the number of elements this witness holds.
#[inline]
- pub fn len(&self) -> usize { self.witness_elements }
+ pub const fn len(&self) -> usize { self.witness_elements }
/// Returns the number of bytes this witness contributes to a transactions total size.
///
@@ -321,7 +321,7 @@ pub struct WitnessDecoder {
impl WitnessDecoder {
/// Constructs a new witness decoder.
- pub fn new() -> Self {
+ pub const fn new() -> Self {
Self {
content: Vec::new(),
cursor: 0,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.