Added documentation to ip_and_cidr_from_string()

This commit is contained in:
Luke Else 2023-02-20 21:25:37 +00:00
parent 6567553f8a
commit 41fc1a3f6d

View File

@ -15,6 +15,18 @@ impl Network {
// fn get_net_id(self) -> u8 {} // fn get_net_id(self) -> u8 {}
} }
/// Function that takes in a string reference and returns the result of splitting a string into
/// both its Address and CIDR
///
/// ```
/// let ip_string = String::from("192.168.0.1/24");
/// let result = match ip_and_cidr_from_string(&ip_string) {
/// Err(_) => panic!(),
/// Ok(ip_and_cidr) => ip_and_cidr
/// };
///
/// >> (IpAddr::V4(192, 168, 0, 1), 24)
/// ```
pub fn ip_and_cidr_from_string(ip_and_cidr: &String) -> Result<(IpAddr, u8), ip::InvalidIPErr>{ pub fn ip_and_cidr_from_string(ip_and_cidr: &String) -> Result<(IpAddr, u8), ip::InvalidIPErr>{
let mut cidr: u8 = Default::default(); let mut cidr: u8 = Default::default();
let mut ip: String = Default::default(); let mut ip: String = Default::default();