use an option

This commit is contained in:
sharks
2018-03-27 21:58:10 -05:00
parent 411c71e900
commit 72326bd96f
3 changed files with 9 additions and 11 deletions

View File

@ -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 '/': {}",