about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJeff Olson <olson.jeffery@gmail.com>2012-04-29 21:53:17 -0700
committerBrian Anderson <banderson@mozilla.com>2012-05-22 22:29:15 -0700
commitd99b7bcb2f0c8163645429bb6ba40ab6761a6ce2 (patch)
tree3934e9b8cdfc186c250ebb92dc7007d702cceffc /src/libstd
parentffdaf14dd90995273fd697b9b87018d5dba84379 (diff)
downloadrust-d99b7bcb2f0c8163645429bb6ba40ab6761a6ce2.tar.gz
rust-d99b7bcb2f0c8163645429bb6ba40ab6761a6ce2.zip
std: pushing existing code in net.rs -> net_ip.rs and re-import/exporting
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/net.rs52
-rw-r--r--src/libstd/net_ip.rs74
-rw-r--r--src/libstd/std.rc1
3 files changed, 80 insertions, 47 deletions
diff --git a/src/libstd/net.rs b/src/libstd/net.rs
index 07bb87d6a06..9d56bef657d 100644
--- a/src/libstd/net.rs
+++ b/src/libstd/net.rs
@@ -1,49 +1,7 @@
-import vec;
-import uint;
+#[doc="
+Top-level module for network-related functionality
+"];
 
-#[doc = "An IP address"]
-enum ip_addr {
-    /*
-    Variant: ipv4
 
-    An IPv4 address
-    */
-    ipv4(u8, u8, u8, u8),
-}
-
-#[doc = "Convert an `ip_addr` to a str"]
-fn format_addr(ip: ip_addr) -> str {
-    alt ip {
-      ipv4(a, b, c, d) {
-        #fmt["%u.%u.%u.%u", a as uint, b as uint, c as uint, d as uint]
-      }
-    }
-}
-
-#[doc = "
-Convert a str to `ip_addr`
-
-Converts a string of the format `x.x.x.x` into an ip_addr enum.
-
-Fails if the string is not a valid IPv4 address
-"]
-fn parse_addr(ip: str) -> ip_addr {
-    let parts = vec::map(str::split_char(ip, '.'), {|s|
-        alt uint::from_str(s) {
-          some(n) if n <= 255u { n }
-          _ { fail "Invalid IP Address part." }
-        }
-    });
-    if vec::len(parts) != 4u { fail "Too many dots in IP address"; }
-    ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8)
-}
-
-#[test]
-fn test_format_ip() {
-    assert (net::format_addr(net::ipv4(127u8, 0u8, 0u8, 1u8)) == "127.0.0.1")
-}
-
-#[test]
-fn test_parse_ip() {
-    assert (net::parse_addr("127.0.0.1") == net::ipv4(127u8, 0u8, 0u8, 1u8));
-}
+import ip = net_ip;
+export ip; 
diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs
new file mode 100644
index 00000000000..ed8fc622b94
--- /dev/null
+++ b/src/libstd/net_ip.rs
@@ -0,0 +1,74 @@
+#[doc="
+Types/fns concerning Internet Protocol (IP), versions 4 & 6
+"];
+
+import vec;
+import uint;
+
+export ip_addr;
+export v4;
+//format_addr, parse_addr;
+
+#[doc = "An IP address"]
+enum ip_addr {
+    #[doc="An IPv4 address"]
+    ipv4(u8, u8, u8, u8),
+}
+
+#[doc="
+Convert a `ip_addr` to a str
+
+# Arguments
+
+* ip - a `std::net::ip::ip_addr`
+"]
+fn format_addr(ip: ip_addr) -> str {
+    alt ip {
+      ipv4(a, b, c, d) {
+        #fmt["%u.%u.%u.%u", a as uint, b as uint, c as uint, d as uint]
+      }
+    }
+}
+
+mod v4 {
+    #[doc = "
+    Convert a str to `ip_addr`
+
+    # Failure
+
+j    Fails if the string is not a valid IPv4 address
+
+    # Arguments
+
+    * ip - a string of the format `x.x.x.x`
+
+    # Returns
+
+    * an `ip_addr` of the `ipv4` variant
+    "]
+    fn parse_addr(ip: str) -> ip_addr {
+        let parts = vec::map(str::split_char(ip, '.'), {|s|
+            alt uint::from_str(s) {
+              some(n) if n <= 255u { n }
+              _ { fail "Invalid IP Address part." }
+            }
+        });
+        if vec::len(parts) != 4u { fail "Too many dots in IP address"; }
+        ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8)
+    }
+}
+
+#[cfg(test)]
+mod test {
+    #[test]
+    fn test_format_ip() {
+        assert (format_addr(ipv4(127u8, 0u8, 0u8, 1u8))
+                == "127.0.0.1")
+    }
+
+    #[test]
+    fn test_parse_ip() {
+        assert (v4::parse_addr("127.0.0.1") ==
+                ipv4(127u8, 0u8, 0u8, 1u8));
+    }
+}
\ No newline at end of file
diff --git a/src/libstd/std.rc b/src/libstd/std.rc
index 99011c5d649..7e2d3b86a41 100644
--- a/src/libstd/std.rc
+++ b/src/libstd/std.rc
@@ -23,6 +23,7 @@ export test, tempfile, serialization;
 // General io and system-services modules
 
 mod net;
+mod net_ip;
 mod net_tcp;
 
 // libuv modules