@@ -494,6 +494,7 @@ fn ipv6_properties() {
494
494
let octets = & [ $( $octet) ,* ] ;
495
495
assert_eq!( & ip!( $s) . octets( ) , octets) ;
496
496
assert_eq!( Ipv6Addr :: from( * octets) , ip!( $s) ) ;
497
+ assert_eq!( Ipv6Addr :: from_octets( * octets) , ip!( $s) ) ;
497
498
498
499
let unspecified: u32 = 1 << 0 ;
499
500
let loopback: u32 = 1 << 1 ;
@@ -846,15 +847,19 @@ fn ipv6_from_constructors() {
846
847
847
848
#[ test]
848
849
fn ipv4_from_octets ( ) {
849
- assert_eq ! ( Ipv4Addr :: from( [ 127 , 0 , 0 , 1 ] ) , Ipv4Addr :: new( 127 , 0 , 0 , 1 ) )
850
+ assert_eq ! ( Ipv4Addr :: from( [ 127 , 0 , 0 , 1 ] ) , Ipv4Addr :: new( 127 , 0 , 0 , 1 ) ) ;
851
+ assert_eq ! ( Ipv4Addr :: from_octets( [ 127 , 0 , 0 , 1 ] ) , Ipv4Addr :: new( 127 , 0 , 0 , 1 ) ) ;
850
852
}
851
853
852
854
#[ test]
853
855
fn ipv6_from_segments ( ) {
854
856
let from_u16s =
855
857
Ipv6Addr :: from ( [ 0x0011 , 0x2233 , 0x4455 , 0x6677 , 0x8899 , 0xaabb , 0xccdd , 0xeeff ] ) ;
858
+ let from_u16s_explicit =
859
+ Ipv6Addr :: from ( [ 0x0011 , 0x2233 , 0x4455 , 0x6677 , 0x8899 , 0xaabb , 0xccdd , 0xeeff ] ) ;
856
860
let new = Ipv6Addr :: new ( 0x0011 , 0x2233 , 0x4455 , 0x6677 , 0x8899 , 0xaabb , 0xccdd , 0xeeff ) ;
857
861
assert_eq ! ( new, from_u16s) ;
862
+ assert_eq ! ( new, from_u16s_explicit) ;
858
863
}
859
864
860
865
#[ test]
@@ -865,7 +870,15 @@ fn ipv6_from_octets() {
865
870
0x00 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 , 0x88 , 0x99 , 0xaa , 0xbb , 0xcc , 0xdd , 0xee ,
866
871
0xff ,
867
872
] ) ;
873
+ let from_u16s_explicit =
874
+ Ipv6Addr :: from_segments ( [ 0x0011 , 0x2233 , 0x4455 , 0x6677 , 0x8899 , 0xaabb , 0xccdd , 0xeeff ] ) ;
875
+ let from_u8s_explicit = Ipv6Addr :: from_octets ( [
876
+ 0x00 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 , 0x88 , 0x99 , 0xaa , 0xbb , 0xcc , 0xdd , 0xee ,
877
+ 0xff ,
878
+ ] ) ;
868
879
assert_eq ! ( from_u16s, from_u8s) ;
880
+ assert_eq ! ( from_u16s, from_u16s_explicit) ;
881
+ assert_eq ! ( from_u16s_explicit, from_u8s_explicit) ;
869
882
}
870
883
871
884
#[ test]
@@ -915,6 +928,9 @@ fn ipv4_const() {
915
928
const OCTETS : [ u8 ; 4 ] = IP_ADDRESS . octets ( ) ;
916
929
assert_eq ! ( OCTETS , [ 127 , 0 , 0 , 1 ] ) ;
917
930
931
+ const FROM_OCTETS : Ipv4Addr = Ipv4Addr :: from_octets ( OCTETS ) ;
932
+ assert_eq ! ( IP_ADDRESS , FROM_OCTETS ) ;
933
+
918
934
const IS_UNSPECIFIED : bool = IP_ADDRESS . is_unspecified ( ) ;
919
935
assert ! ( !IS_UNSPECIFIED ) ;
920
936
@@ -971,9 +987,15 @@ fn ipv6_const() {
971
987
const SEGMENTS : [ u16 ; 8 ] = IP_ADDRESS . segments ( ) ;
972
988
assert_eq ! ( SEGMENTS , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ) ;
973
989
990
+ const FROM_SEGMENTS : Ipv6Addr = Ipv6Addr :: from_segments ( SEGMENTS ) ;
991
+ assert_eq ! ( IP_ADDRESS , FROM_SEGMENTS ) ;
992
+
974
993
const OCTETS : [ u8 ; 16 ] = IP_ADDRESS . octets ( ) ;
975
994
assert_eq ! ( OCTETS , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ) ;
976
995
996
+ const FROM_OCTETS : Ipv6Addr = Ipv6Addr :: from_octets ( OCTETS ) ;
997
+ assert_eq ! ( IP_ADDRESS , FROM_OCTETS ) ;
998
+
977
999
const IS_UNSPECIFIED : bool = IP_ADDRESS . is_unspecified ( ) ;
978
1000
assert ! ( !IS_UNSPECIFIED ) ;
979
1001
0 commit comments