Split parse macros

Done in preparation for enabling no-alloc builds.

Split the macro calls to handle `str` separately from `alloc` types.
This commit is contained in:
Tobin C. Harding 2024-11-01 17:47:22 +11:00
parent 515c0f584a
commit 88f6621e30
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 6 additions and 7 deletions

View File

@ -2,8 +2,6 @@
//! Provides [`Height`] and [`Time`] types used by the `rust-bitcoin` `absolute::LockTime` type. //! Provides [`Height`] and [`Time`] types used by the `rust-bitcoin` `absolute::LockTime` type.
#[cfg(feature = "alloc")]
use alloc::{boxed::Box, string::String};
use core::fmt; use core::fmt;
use internals::error::InputString; use internals::error::InputString;

View File

@ -107,10 +107,9 @@ macro_rules! impl_tryfrom_str_from_int_infallible {
#[macro_export] #[macro_export]
macro_rules! impl_parse_str_from_int_infallible { macro_rules! impl_parse_str_from_int_infallible {
($to:ident, $inner:ident, $fn:ident) => { ($to:ident, $inner:ident, $fn:ident) => {
#[cfg(all(feature = "alloc", not(feature = "std")))] $crate::impl_tryfrom_str_from_int_infallible!(&str, $to, $inner, $fn);
$crate::impl_tryfrom_str_from_int_infallible!(&str, $to, $inner, $fn; alloc::string::String, $to, $inner, $fn; alloc::boxed::Box<str>, $to, $inner, $fn); #[cfg(feature = "alloc")]
#[cfg(feature = "std")] $crate::impl_tryfrom_str_from_int_infallible!(alloc::string::String, $to, $inner, $fn; alloc::boxed::Box<str>, $to, $inner, $fn);
$crate::impl_tryfrom_str_from_int_infallible!(&str, $to, $inner, $fn; std::string::String, $to, $inner, $fn; std::boxed::Box<str>, $to, $inner, $fn);
impl core::str::FromStr for $to { impl core::str::FromStr for $to {
type Err = $crate::parse::ParseIntError; type Err = $crate::parse::ParseIntError;
@ -143,7 +142,9 @@ macro_rules! impl_tryfrom_str {
#[macro_export] #[macro_export]
macro_rules! impl_parse_str { macro_rules! impl_parse_str {
($to:ty, $err:ty, $inner_fn:expr) => { ($to:ty, $err:ty, $inner_fn:expr) => {
$crate::impl_tryfrom_str!(&str, $to, $err, $inner_fn; String, $to, $err, $inner_fn; Box<str>, $to, $err, $inner_fn); $crate::impl_tryfrom_str!(&str, $to, $err, $inner_fn);
#[cfg(feature = "alloc")]
$crate::impl_tryfrom_str!(alloc::string::String, $to, $err, $inner_fn; alloc::boxed::Box<str>, $to, $err, $inner_fn);
impl core::str::FromStr for $to { impl core::str::FromStr for $to {
type Err = $err; type Err = $err;