Skip to content

Commit

Permalink
segwit: Inline functions
Browse files Browse the repository at this point in the history
As we do, inline "small" public functions in the `segwit` module.
  • Loading branch information
tcharding committed Sep 11, 2023
1 parent 1867dcf commit a774bc1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use crate::write_err;
/// let (_hrp, _witness_version, _witness_program) = segwit::decode(address).expect("failed to decode address");
/// ```
#[cfg(feature = "alloc")]
#[inline]
pub fn decode(s: &str) -> Result<(Hrp, Fe32, Vec<u8>), SegwitHrpstringError> {
let segwit = SegwitHrpstring::new(s)?;
Ok((segwit.hrp(), segwit.witness_version(), segwit.byte_iter().collect::<Vec<u8>>()))
Expand All @@ -85,6 +86,7 @@ pub fn decode(s: &str) -> Result<(Hrp, Fe32, Vec<u8>), SegwitHrpstringError> {
/// [BIP-173]: <https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki>
/// [BIP-350]: <https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki>
#[cfg(feature = "alloc")]
#[inline]
pub fn encode(
hrp: &Hrp,
witness_version: Fe32,
Expand All @@ -100,12 +102,14 @@ pub fn encode(

/// Encodes a segwit version 0 address.
#[cfg(feature = "alloc")]
#[inline]
pub fn encode_v0(hrp: &Hrp, witness_program: &[u8]) -> Result<String, EncodeError> {
encode(hrp, VERSION_0, witness_program)
}

/// Encodes a segwit version 1 address.
#[cfg(feature = "alloc")]
#[inline]
pub fn encode_v1(hrp: &Hrp, witness_program: &[u8]) -> Result<String, EncodeError> {
encode(hrp, VERSION_1, witness_program)
}
Expand All @@ -114,6 +118,7 @@ pub fn encode_v1(hrp: &Hrp, witness_program: &[u8]) -> Result<String, EncodeErro
///
/// Does not check the validity of the witness version and witness program lengths (see
/// the [`crate::primitives::segwit`] module for validation functions).
#[inline]
pub fn encode_to_fmt_unchecked<W: fmt::Write>(
fmt: &mut W,
hrp: &Hrp,
Expand Down Expand Up @@ -142,6 +147,7 @@ pub fn encode_to_fmt_unchecked<W: fmt::Write>(
///
/// Does not check the validity of the witness version and witness program lengths (see
/// the [`crate::primitives::segwit`] module for validation functions).
#[inline]
pub fn encode_to_fmt_unchecked_uppercase<W: fmt::Write>(
fmt: &mut W,
hrp: &Hrp,
Expand Down

0 comments on commit a774bc1

Please sign in to comment.