Skip to content

Commit

Permalink
update imports and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pront committed Nov 30, 2023
1 parent 9576c61 commit ce9d5d2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/stdlib/ip_cidr_contains.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::compiler::prelude::*;
use cidr_utils::cidr::IpCidr;
use std::net::IpAddr;
use std::str::FromStr;

fn ip_cidr_contains(value: Value, cidr: Value) -> Resolved {
let value = value
.try_bytes_utf8_lossy()?
.parse()
.map_err(|err| format!("unable to parse IP address: {err}"))?;
let bytes = value.try_bytes_utf8_lossy()?;
let ip_addr =
IpAddr::from_str(&bytes).map_err(|err| format!("unable to parse IP address: {err}"))?;
let cidr = {
let cidr = cidr.try_bytes_utf8_lossy()?;

IpCidr::from_str(cidr).map_err(|err| format!("unable to parse CIDR: {err}"))?
IpCidr::from_str(&cidr).map_err(|err| format!("unable to parse CIDR: {err}"))?
};
Ok(cidr.contains(value).into())
Ok(cidr.contains(&ip_addr).into())
}

#[derive(Clone, Copy, Debug)]
Expand Down

0 comments on commit ce9d5d2

Please sign in to comment.