提交 e2051850 编写于 作者: T Tom Lee

IterBytes for IpAddr and SocketAddr

上级 b66ec348
......@@ -14,11 +14,12 @@
use option::{Option, None, Some};
use str::StrSlice;
use to_str::ToStr;
use to_bytes::IterBytes;
use vec::{MutableCloneableVector, ImmutableVector, MutableVector};
pub type Port = u16;
#[deriving(Eq, TotalEq, Clone)]
#[deriving(Eq, TotalEq, Clone, IterBytes)]
pub enum IpAddr {
Ipv4Addr(u8, u8, u8, u8),
Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16)
......@@ -48,7 +49,7 @@ fn to_str(&self) -> ~str {
}
}
#[deriving(Eq, TotalEq, Clone)]
#[deriving(Eq, TotalEq, Clone, IterBytes)]
pub struct SocketAddr {
ip: IpAddr,
port: Port,
......@@ -339,6 +340,7 @@ fn from_str(s: &str) -> Option<SocketAddr> {
mod test {
use prelude::*;
use super::*;
use to_bytes::ToBytes;
#[test]
fn test_from_str_ipv4() {
......@@ -441,4 +443,13 @@ fn ipv6_addr_to_str() {
assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_str(), ~"8:9:a:b:c:d:e:f");
}
#[test]
fn ipv4_addr_to_bytes() {
Ipv4Addr(123, 20, 12, 56).to_bytes(true);
}
#[test]
fn socket_addr_to_bytes() {
SocketAddr { ip: Ipv4Addr(1, 2, 3, 4), port: 1234 }.to_bytes(true);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册