Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8cb1c63

Browse files
constify comparison traits on network addresses
1 parent c966ab8 commit 8cb1c63

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

‎library/core/src/net/ip_addr.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ pub enum IpAddr {
6868
/// assert!("0xcb.0x0.0x71.0x00".parse::<Ipv4Addr>().is_err()); // all octets are in hex
6969
/// ```
7070
#[rustc_diagnostic_item = "Ipv4Addr"]
71-
#[derive(Copy, Clone, PartialEq, Eq)]
71+
#[derive(Copy, Clone)]
72+
#[derive_const(PartialEq, Eq)]
7273
#[stable(feature = "rust1", since = "1.0.0")]
7374
pub struct Ipv4Addr {
7475
octets: [u8; 4],
@@ -161,7 +162,8 @@ impl Hash for Ipv4Addr {
161162
/// assert_eq!(localhost.is_loopback(), true);
162163
/// ```
163164
#[rustc_diagnostic_item = "Ipv6Addr"]
164-
#[derive(Copy, Clone, PartialEq, Eq)]
165+
#[derive(Copy, Clone)]
166+
#[derive_const(PartialEq, Eq)]
165167
#[stable(feature = "rust1", since = "1.0.0")]
166168
pub struct Ipv6Addr {
167169
octets: [u8; 16],
@@ -1183,7 +1185,8 @@ impl PartialEq<IpAddr> for Ipv4Addr {
11831185
}
11841186

11851187
#[stable(feature = "rust1", since = "1.0.0")]
1186-
impl PartialOrd for Ipv4Addr {
1188+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1189+
impl const PartialOrd for Ipv4Addr {
11871190
#[inline]
11881191
fn partial_cmp(&self, other: &Ipv4Addr) -> Option<Ordering> {
11891192
Some(self.cmp(other))
@@ -1213,7 +1216,8 @@ impl PartialOrd<IpAddr> for Ipv4Addr {
12131216
}
12141217

12151218
#[stable(feature = "rust1", since = "1.0.0")]
1216-
impl Ord for Ipv4Addr {
1219+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
1220+
impl const Ord for Ipv4Addr {
12171221
#[inline]
12181222
fn cmp(&self, other: &Ipv4Addr) -> Ordering {
12191223
self.octets.cmp(&other.octets)
@@ -2177,7 +2181,8 @@ impl PartialEq<Ipv6Addr> for IpAddr {
21772181
}
21782182

21792183
#[stable(feature = "rust1", since = "1.0.0")]
2180-
impl PartialOrd for Ipv6Addr {
2184+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2185+
impl const PartialOrd for Ipv6Addr {
21812186
#[inline]
21822187
fn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering> {
21832188
Some(self.cmp(other))
@@ -2207,7 +2212,8 @@ impl PartialOrd<IpAddr> for Ipv6Addr {
22072212
}
22082213

22092214
#[stable(feature = "rust1", since = "1.0.0")]
2210-
impl Ord for Ipv6Addr {
2215+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2216+
impl const Ord for Ipv6Addr {
22112217
#[inline]
22122218
fn cmp(&self, other: &Ipv6Addr) -> Ordering {
22132219
self.segments().cmp(&other.segments())

‎library/core/src/net/socket_addr.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr};
2828
/// assert_eq!(socket.port(), 8080);
2929
/// assert_eq!(socket.is_ipv4(), true);
3030
/// ```
31-
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
31+
#[derive(Copy, Clone, Hash)]
32+
#[derive_const(PartialEq, Eq, PartialOrd, Ord)]
3233
#[stable(feature = "rust1", since = "1.0.0")]
3334
pub enum SocketAddr {
3435
/// An IPv4 socket address.
@@ -76,7 +77,8 @@ pub enum SocketAddr {
7677
/// assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1));
7778
/// assert_eq!(socket.port(), 8080);
7879
/// ```
79-
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
80+
#[derive(Copy, Clone, Hash)]
81+
#[derive_const(Eq, PartialEq, Ord, PartialOrd)]
8082
#[stable(feature = "rust1", since = "1.0.0")]
8183
pub struct SocketAddrV4 {
8284
ip: Ipv4Addr,
@@ -142,7 +144,8 @@ pub struct SocketAddrV4 {
142144
/// with_scope.set_scope_id(3);
143145
/// assert_eq!("[2001:db8::1%3]:8080".parse(), Ok(with_scope));
144146
/// ```
145-
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
147+
#[derive(Copy, Clone, Hash)]
148+
#[derive_const(Eq, PartialEq, Ord, PartialOrd)]
146149
#[stable(feature = "rust1", since = "1.0.0")]
147150
pub struct SocketAddrV6 {
148151
ip: Ipv6Addr,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /