Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

mod error;

use core::num::NonZeroU32;
use core::ops;
use core::str::FromStr;

Expand Down Expand Up @@ -679,7 +680,7 @@ impl<'a> Tree<'a> {
}

/// Parse a string as a u32, forbidding zero.
pub fn parse_num_nonzero(s: &str, context: &'static str) -> Result<u32, ParseNumError> {
pub fn parse_num_nonzero(s: &str, context: &'static str) -> Result<NonZeroU32, ParseNumError> {
if s == "0" {
return Err(ParseNumError::IllegalZero { context });
}
Expand All @@ -688,7 +689,7 @@ pub fn parse_num_nonzero(s: &str, context: &'static str) -> Result<u32, ParseNum
return Err(ParseNumError::InvalidLeadingDigit(ch));
}
}
u32::from_str(s).map_err(ParseNumError::StdParse)
NonZeroU32::from_str(s).map_err(ParseNumError::StdParse)
}

/// Parse a string as a u32, for timelocks or thresholds
Expand All @@ -697,7 +698,7 @@ pub fn parse_num(s: &str) -> Result<u32, ParseNumError> {
// Special-case 0 since it is the only number which may start with a leading zero.
return Ok(0);
}
parse_num_nonzero(s, "")
parse_num_nonzero(s, "").map(u32::from)
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub use crate::miniscript::satisfy::{Preimage32, Satisfier};
pub use crate::miniscript::{hash256, Miniscript};
use crate::prelude::*;
pub use crate::primitives::absolute_locktime::{AbsLockTime, AbsLockTimeError};
pub use crate::primitives::positive_f64::PositiveF64;
pub use crate::primitives::relative_locktime::{RelLockTime, RelLockTimeError};
pub use crate::primitives::threshold::{Threshold, ThresholdError};
pub use crate::validation::{Error as ValidationError, ValidationParams};
Expand Down
Loading
Loading