@@ -1068,6 +1068,14 @@ impl From<[u8; 16]> for Ipv6Addr {
1068
1068
}
1069
1069
}
1070
1070
1071
+ #[ stable( feature = "ipv6_from_segments" , since = "1.15.0" ) ]
1072
+ impl From < [ u16 ; 8 ] > for Ipv6Addr {
1073
+ fn from ( segments : [ u16 ; 8 ] ) -> Ipv6Addr {
1074
+ let [ a, b, c, d, e, f, g, h] = segments;
1075
+ Ipv6Addr :: new ( a, b, c, d, e, f, g, h)
1076
+ }
1077
+ }
1078
+
1071
1079
// Tests for this module
1072
1080
#[ cfg( all( test, not( target_os = "emscripten" ) ) ) ]
1073
1081
mod tests {
@@ -1413,10 +1421,28 @@ mod tests {
1413
1421
}
1414
1422
1415
1423
#[ test]
1416
- fn ipv4_from_u32_slice ( ) {
1424
+ fn ipv4_from_octets ( ) {
1417
1425
assert_eq ! ( Ipv4Addr :: from( [ 127 , 0 , 0 , 1 ] ) , Ipv4Addr :: new( 127 , 0 , 0 , 1 ) )
1418
1426
}
1419
1427
1428
+ #[ test]
1429
+ fn ipv6_from_segments ( ) {
1430
+ let from_u16s = Ipv6Addr :: from ( [ 0x0011 , 0x2233 , 0x4455 , 0x6677 ,
1431
+ 0x8899 , 0xaabb , 0xccdd , 0xeeff ] ) ;
1432
+ let new = Ipv6Addr :: new ( 0x0011 , 0x2233 , 0x4455 , 0x6677 ,
1433
+ 0x8899 , 0xaabb , 0xccdd , 0xeeff ) ;
1434
+ assert_eq ! ( new, from_u16s) ;
1435
+ }
1436
+
1437
+ #[ test]
1438
+ fn ipv6_from_octets ( ) {
1439
+ let from_u16s = Ipv6Addr :: from ( [ 0x0011 , 0x2233 , 0x4455 , 0x6677 ,
1440
+ 0x8899 , 0xaabb , 0xccdd , 0xeeff ] ) ;
1441
+ let from_u8s = Ipv6Addr :: from ( [ 0x00 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 ,
1442
+ 0x88 , 0x99 , 0xaa , 0xbb , 0xcc , 0xdd , 0xee , 0xff ] ) ;
1443
+ assert_eq ! ( from_u16s, from_u8s) ;
1444
+ }
1445
+
1420
1446
#[ test]
1421
1447
fn ord ( ) {
1422
1448
assert ! ( Ipv4Addr :: new( 100 , 64 , 3 , 3 ) < Ipv4Addr :: new( 192 , 0 , 2 , 2 ) ) ;
0 commit comments