From c796c947c9237849eeb59087894535a4600b2386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Tue, 25 Jun 2024 11:21:56 +0200 Subject: [PATCH] reorder functions --- src/parsers/combinators.rs | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/parsers/combinators.rs b/src/parsers/combinators.rs index c54caa8..5d2a1f9 100644 --- a/src/parsers/combinators.rs +++ b/src/parsers/combinators.rs @@ -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( +/// 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( s: &str, address_parser: AP, host_parser: NP, @@ -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( - s: &str, - address_parser: AP, -) -> Result +/// 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(s: &str, address_parser: AP) -> Result where AP: Fn(&str) -> Result, { @@ -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( +/// Similar to [`parse_any_cidr_full`] but ignores host bits in addresses. +pub fn parse_any_cidr_full_ignore_hostbits( s: &str, address_parser: AP, host_parser: NP, @@ -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(s: &str, address_parser: AP) -> Result +/// Similar to [`parse_any_cidr`] but ignores host bits in addresses. +pub fn parse_any_cidr_ignore_hostbits( + s: &str, + address_parser: AP, +) -> Result where AP: Fn(&str) -> Result, {