mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-16 08:48:51 +00:00
use an option
This commit is contained in:
@ -32,12 +32,12 @@ impl Error for IpNetworkError {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cidr_parts(cidr: &str) -> Result<(&str, &str), IpNetworkError> {
|
||||
pub fn cidr_parts(cidr: &str) -> Result<(&str, Option<&str>), IpNetworkError> {
|
||||
let parts = cidr.split('/').collect::<Vec<&str>>();
|
||||
if parts.len() == 1 {
|
||||
Ok((parts[0], ""))
|
||||
Ok((parts[0], None))
|
||||
} else if parts.len() == 2 {
|
||||
Ok((parts[0], parts[1]))
|
||||
Ok((parts[0], Some(parts[1])))
|
||||
} else {
|
||||
Err(IpNetworkError::InvalidCidrFormat(format!(
|
||||
"CIDR must contain a single '/': {}",
|
||||
|
Reference in New Issue
Block a user