Skip to content

Commit

Permalink
Feature gate the segwit::EncodeError
Browse files Browse the repository at this point in the history
This error is only used if the "alloc" feature is enabled, feature gate
it.
  • Loading branch information
tcharding committed Jan 27, 2024
1 parent 9aca6a9 commit 1f773b9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl From<SegwitHrpstringError> for DecodeError {
/// An error while constructing a [`SegwitHrpstring`] type.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
#[cfg(feature = "alloc")]
pub enum EncodeError {
/// Invalid witness version (must be 0-16 inclusive).
WitnessVersion(InvalidWitnessVersionError),
Expand All @@ -385,6 +386,7 @@ pub enum EncodeError {
Fmt(fmt::Error),
}

#[cfg(feature = "alloc")]
impl fmt::Display for EncodeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use EncodeError::*;
Expand All @@ -399,6 +401,7 @@ impl fmt::Display for EncodeError {
}

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
impl std::error::Error for EncodeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use EncodeError::*;
Expand All @@ -412,21 +415,25 @@ impl std::error::Error for EncodeError {
}
}

#[cfg(feature = "alloc")]
impl From<InvalidWitnessVersionError> for EncodeError {
#[inline]
fn from(e: InvalidWitnessVersionError) -> Self { Self::WitnessVersion(e) }
}

#[cfg(feature = "alloc")]
impl From<WitnessLengthError> for EncodeError {
#[inline]
fn from(e: WitnessLengthError) -> Self { Self::WitnessLength(e) }
}

#[cfg(feature = "alloc")]
impl From<SegwitCodeLengthError> for EncodeError {
#[inline]
fn from(e: SegwitCodeLengthError) -> Self { Self::TooLong(e) }
}

#[cfg(feature = "alloc")]
impl From<fmt::Error> for EncodeError {
#[inline]
fn from(e: fmt::Error) -> Self { Self::Fmt(e) }
Expand Down

0 comments on commit 1f773b9

Please sign in to comment.