Skip to content

Commit a5049f7

Browse files
Add ::1 example in IPv6 to IPv4 conversion
1 parent 1a91fc6 commit a5049f7

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

src/libstd/net/ip.rs

+44-15
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,15 @@ impl Ipv6Addr {
646646
/// # Examples
647647
///
648648
/// ```
649+
/// #![feature(ip)]
650+
///
649651
/// use std::net::Ipv6Addr;
650652
///
651-
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(), false);
652-
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true);
653+
/// fn main() {
654+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(),
655+
/// false);
656+
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true);
657+
/// }
653658
/// ```
654659
pub fn is_unique_local(&self) -> bool {
655660
(self.segments()[0] & 0xfe00) == 0xfc00
@@ -664,11 +669,15 @@ impl Ipv6Addr {
664669
/// # Examples
665670
///
666671
/// ```
672+
/// #![feature(ip)]
673+
///
667674
/// use std::net::Ipv6Addr;
668675
///
669-
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_link_local(),
670-
/// false);
671-
/// assert_eq!(Ipv6Addr::new(0xfe8a, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true);
676+
/// fn main() {
677+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_link_local(),
678+
/// false);
679+
/// assert_eq!(Ipv6Addr::new(0xfe8a, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true);
680+
/// }
672681
/// ```
673682
pub fn is_unicast_link_local(&self) -> bool {
674683
(self.segments()[0] & 0xffc0) == 0xfe80
@@ -680,11 +689,15 @@ impl Ipv6Addr {
680689
/// # Examples
681690
///
682691
/// ```
692+
/// #![feature(ip)]
693+
///
683694
/// use std::net::Ipv6Addr;
684695
///
685-
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_site_local(),
686-
/// false);
687-
/// assert_eq!(Ipv6Addr::new(0xfec2, 0, 0, 0, 0, 0, 0, 0).is_unicast_site_local(), true);
696+
/// fn main() {
697+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_site_local(),
698+
/// false);
699+
/// assert_eq!(Ipv6Addr::new(0xfec2, 0, 0, 0, 0, 0, 0, 0).is_unicast_site_local(), true);
700+
/// }
688701
/// ```
689702
pub fn is_unicast_site_local(&self) -> bool {
690703
(self.segments()[0] & 0xffc0) == 0xfec0
@@ -700,10 +713,15 @@ impl Ipv6Addr {
700713
/// # Examples
701714
///
702715
/// ```
716+
/// #![feature(ip)]
717+
///
703718
/// use std::net::Ipv6Addr;
704719
///
705-
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false);
706-
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
720+
/// fn main() {
721+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(),
722+
/// false);
723+
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
724+
/// }
707725
/// ```
708726
pub fn is_documentation(&self) -> bool {
709727
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
@@ -723,10 +741,15 @@ impl Ipv6Addr {
723741
/// # Examples
724742
///
725743
/// ```
744+
/// #![feature(ip)]
745+
///
726746
/// use std::net::Ipv6Addr;
727747
///
728-
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast_global(), false);
729-
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_global(), true);
748+
/// fn main() {
749+
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast_global(), false);
750+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_global(),
751+
/// true);
752+
/// }
730753
/// ```
731754
pub fn is_unicast_global(&self) -> bool {
732755
!self.is_multicast()
@@ -740,11 +763,15 @@ impl Ipv6Addr {
740763
/// # Examples
741764
///
742765
/// ```
766+
/// #![feature(ip)]
767+
///
743768
/// use std::net::{Ipv6Addr, Ipv6MulticastScope};
744769
///
745-
/// assert_eq!(Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0).multicast_scope(),
746-
/// Some(Ipv6MulticastScope::Global));
747-
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).multicast_scope(), None);
770+
/// fn main() {
771+
/// assert_eq!(Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0).multicast_scope(),
772+
/// Some(Ipv6MulticastScope::Global));
773+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).multicast_scope(), None);
774+
/// }
748775
/// ```
749776
pub fn multicast_scope(&self) -> Option<Ipv6MulticastScope> {
750777
if self.is_multicast() {
@@ -792,6 +819,8 @@ impl Ipv6Addr {
792819
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4(), None);
793820
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(),
794821
/// Some(Ipv4Addr::new(192, 10, 2, 255)));
822+
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(),
823+
/// Some(Ipv4Addr::new(0, 0, 0, 1)));
795824
/// ```
796825
#[stable(feature = "rust1", since = "1.0.0")]
797826
pub fn to_ipv4(&self) -> Option<Ipv4Addr> {

0 commit comments

Comments
 (0)