From d5ec71a000b2ba0a1b591e379566a8205ad6ad6a Mon Sep 17 00:00:00 2001 From: Luke Else Date: Sat, 11 Feb 2023 16:35:30 +0000 Subject: [PATCH] Added documentation to FromString trait on IpAddr --- src/networking/ip.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/networking/ip.rs b/src/networking/ip.rs index c88708e..e252a68 100644 --- a/src/networking/ip.rs +++ b/src/networking/ip.rs @@ -32,6 +32,16 @@ impl ToString for IpAddr { impl FromStr for IpAddr { type Err = InvalidIPErr; /// Function that generates a IpAddr / Err from a string + /// + /// # Limitation + /// Currently only works for IPs of type IPv4 + /// # Example + /// ``` + /// let ip: &str = "127.0.0.1"; + /// + /// let parsed_ip: IpAddr = IpAddr::from_str(ip); + /// ///parsed_ip = IpAddr::V4(127,0,0,1) + /// ``` fn from_str(s: &str) -> Result { let split_ip = s.split('.'); if split_ip.clone().count() != 4 { @@ -86,6 +96,8 @@ mod tests { #[test] #[should_panic] + ///Tests if an invalid Ip will cause a panic when + /// converting from a string to an IpAddr fn invalid_string_to_ip() { use super::*; let ip = "Hello, world";