Skip to content

Commit

Permalink
reorder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
stbuehler committed Jun 25, 2024
1 parent 9d3b38b commit c796c94
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/parsers/combinators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ where

/// Parse [`AnyIpCidr`] with custom address and network (when no '/' separator was found) parser
///
/// Similar to [`parse_any_cidr_full`] but ignores host bits in addresses.
pub fn parse_any_cidr_full_ignore_hostbits<AP, NP>(
/// If a '/' is found, parse trailing number as prefix length and leading address with `address_parser`.
/// Otherwise parse with `host_parser`.
pub fn parse_any_cidr_full<AP, NP>(
s: &str,
address_parser: AP,
host_parser: NP,
Expand All @@ -97,21 +98,16 @@ where
{
match s.rfind('/') {
None => host_parser(s),
Some(pos) => Ok(
IpInet::new(address_parser(&s[0..pos])?, s[pos + 1..].parse()?)?
.network()
.into(),
),
Some(pos) => AnyIpCidr::new(address_parser(&s[0..pos])?, s[pos + 1..].parse()?),
}
}

/// Parse [`AnyIpCidr`] with custom address parser
///
/// Similar to [`parse_any_cidr`] but ignores host bits in addresses.
pub fn parse_any_cidr_ignore_hostbits<AP>(
s: &str,
address_parser: AP,
) -> Result<AnyIpCidr, NetworkParseError>
/// If a '/' is found, parse trailing number as prefix length and leading address with `address_parser`.
/// If input is just `"any"` returns [`AnyIpCidr::Any`].
/// Otherwise parse `address_parser` and treat as host (maximum prefix length).
pub fn parse_any_cidr<AP>(s: &str, address_parser: AP) -> Result<AnyIpCidr, NetworkParseError>
where
AP: Fn(&str) -> Result<IpAddr, AddrParseError>,
{
Expand All @@ -126,9 +122,8 @@ where

/// Parse [`AnyIpCidr`] with custom address and network (when no '/' separator was found) parser
///
/// If a '/' is found, parse trailing number as prefix length and leading address with `address_parser`.
/// Otherwise parse with `host_parser`.
pub fn parse_any_cidr_full<AP, NP>(
/// Similar to [`parse_any_cidr_full`] but ignores host bits in addresses.
pub fn parse_any_cidr_full_ignore_hostbits<AP, NP>(
s: &str,
address_parser: AP,
host_parser: NP,
Expand All @@ -139,16 +134,21 @@ where
{
match s.rfind('/') {
None => host_parser(s),
Some(pos) => AnyIpCidr::new(address_parser(&s[0..pos])?, s[pos + 1..].parse()?),
Some(pos) => Ok(
IpInet::new(address_parser(&s[0..pos])?, s[pos + 1..].parse()?)?
.network()
.into(),
),
}
}

/// Parse [`AnyIpCidr`] with custom address parser
///
/// If a '/' is found, parse trailing number as prefix length and leading address with `address_parser`.
/// If input is just `"any"` returns [`AnyIpCidr::Any`].
/// Otherwise parse `address_parser` and treat as host (maximum prefix length).
pub fn parse_any_cidr<AP>(s: &str, address_parser: AP) -> Result<AnyIpCidr, NetworkParseError>
/// Similar to [`parse_any_cidr`] but ignores host bits in addresses.
pub fn parse_any_cidr_ignore_hostbits<AP>(
s: &str,
address_parser: AP,
) -> Result<AnyIpCidr, NetworkParseError>
where
AP: Fn(&str) -> Result<IpAddr, AddrParseError>,
{
Expand Down

0 comments on commit c796c94

Please sign in to comment.