pub fn check_subnet(ip: impl Into<String>, range: impl Into<String>) -> Result<bool, String> {
    let ip = ip.into();
    let range = range.into();
    let v: Vec<&str> = range.split("/").collect();
    if v.len() != 2 {
        return Err(String::from(""));
    };
    let ip_bit = match get_bit(&ip) {
        Ok(ip_bit) => ip_bit,
        Err(e) => return Err(e),
    };
    let cidr_ip = match get_bit(v[0]) {
        Ok(ip_bit) => ip_bit,
        Err(e) => return Err(e),
    };
    let cidr: u8 = match v[1].parse() {
        Ok(cidr) => cidr,
        Err(e) => return Err(e.to_string()),
    };
    if 0 >= cidr || cidr > 32 {
        return Err(String::from(
            "cidr must be more than 0 and less than or equal to 32",
        ));
    }
    let ip_bit_num = match u64::from_str_radix(&ip_bit, 2) {
        Ok(ip_bit_num) => ip_bit_num,
        Err(e) => return Err(e.to_string()),
    };
    let cidr_bit_num = match u64::from_str_radix(&cidr_ip, 2) {
        Ok(cidr_bit_num) => cidr_bit_num,
        Err(e) => return Err(e.to_string()),
    };
    Ok((ip_bit_num >> (32 - cidr)) ^ (cidr_bit_num >> (32 - cidr)) == 0)
}
/// Returns whether the ip address is included in the address space.
///
/// # Example
/// ```
/// match check_subnet("123.123.123.123", "123.123.0.0/16") {
///     Ok(checked) => println!("Is your ip address included in the specified address space? [{}].", checked),
///     Err(_) => println!("your input is invalid.")
/// }
/// ```
Returns whether the ip address is included in the address space.
Returns whether the ip address is included in the address space .
pub fn check_subnet(ip: impl Into<String>, range: impl Into<String>) -> Result<bool, String> {
    let ip = ip.into();
    let range = range.into();
    let v: Vec<&str> = range.split("/").collect();
    if v.len() != 2 {
        return Err(String::from(""));
    };
    let ip_bit = match get_bit(&ip) {
        Ok(ip_bit) => ip_bit,
        Err(e) => return Err(e),
    };
    let cidr_ip = match get_bit(v[0]) {
        Ok(ip_bit) => ip_bit,
        Err(e) => return Err(e),
    };
    let cidr: u8 = match v[1].parse() {
        Ok(cidr) => cidr,
        Err(e) => return Err(e.to_string()),
    };
    if 0 >= cidr || cidr > 32 {
        return Err(String::from(
            "cidr must be more than 0 and less than or equal to 32",
        ));
    }
    let ip_bit_num = match u64::from_str_radix(&ip_bit, 2) {
        Ok(ip_bit_num) => ip_bit_num,
        Err(e) => return Err(e.to_string()),
    };
    let cidr_bit_num = match u64::from_str_radix(&cidr_ip, 2) {
        Ok(cidr_bit_num) => cidr_bit_num,
        Err(e) => return Err(e.to_string()),
    };
    Ok((ip_bit_num >> (32 - cidr)) ^ (cidr_bit_num >> (32 - cidr)) == 0)
}
pub fn check_subnet ( ip : impl Into < String > , range : impl Into < String > ) -> Result < bool , String > { let ip = ip . into ( ) ; let range = range . into ( ) ; let v : Vec < & str > = range . split ( " " ) . collect ( ) ; if v . len ( ) != 2 { return Err ( String :: from ( " " ) ) ; } ; let ip_bit = match get_bit ( & ip ) { Ok ( ip_bit ) => ip_bit , Err ( e ) => return Err ( e ) , } ; let cidr_ip = match get_bit ( v [ 0 ] ) { Ok ( ip_bit ) => ip_bit , Err ( e ) => return Err ( e ) , } ; let cidr : u8 = match v [ 1 ] . parse ( ) { Ok ( cidr ) => cidr , Err ( e ) => return Err ( e . to_string ( ) ) , } ; if 0 >= cidr || cidr > 32 { return Err ( String :: from ( " " , ) ) ; } let ip_bit_num = match u64 :: from_str_radix ( & ip_bit , 2 ) { Ok ( ip_bit_num ) => ip_bit_num , Err ( e ) => return Err ( e . to_string ( ) ) , } ; let cidr_bit_num = match u64 :: from_str_radix ( & cidr_ip , 2 ) { Ok ( cidr_bit_num ) => cidr_bit_num , Err ( e ) => return Err ( e . to_string ( ) ) , } ; Ok ( ( ip_bit_num >> ( 32 - cidr ) ) ^ ( cidr_bit_num >> ( 32 - cidr ) ) == 0 ) }
Returns whether the ip address is included in the address space.
Returns whether the ip address is included in the address space .
ip
impl Into<String>
range
impl Into<String>
example
None