Skip to content

Commit 7783695

Browse files
committed
core::net: Rename parse_ascii() fns to from_bytes()
We are operating on u8 (aka. byte) values here. ASCII only allows values from 0-127. This would also be consistent with the naming of `OsStr::from_bytes()`.
1 parent 707d8c3 commit 7783695

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

library/core/src/net/parser.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ impl IpAddr {
282282
/// let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
283283
/// let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
284284
///
285-
/// assert_eq!(IpAddr::parse_ascii(b"127.0.0.1"), Ok(localhost_v4));
286-
/// assert_eq!(IpAddr::parse_ascii(b"::1"), Ok(localhost_v6));
285+
/// assert_eq!(IpAddr::from_bytes(b"127.0.0.1"), Ok(localhost_v4));
286+
/// assert_eq!(IpAddr::from_bytes(b"::1"), Ok(localhost_v6));
287287
/// ```
288288
#[unstable(feature = "addr_parse_ascii", issue = "101035")]
289-
pub fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError> {
289+
pub fn from_bytes(b: &[u8]) -> Result<Self, AddrParseError> {
290290
Parser::new(b).parse_with(|p| p.read_ip_addr(), AddrKind::Ip)
291291
}
292292
}
@@ -295,7 +295,7 @@ impl IpAddr {
295295
impl FromStr for IpAddr {
296296
type Err = AddrParseError;
297297
fn from_str(s: &str) -> Result<IpAddr, AddrParseError> {
298-
Self::parse_ascii(s.as_bytes())
298+
Self::from_bytes(s.as_bytes())
299299
}
300300
}
301301

@@ -309,10 +309,10 @@ impl Ipv4Addr {
309309
///
310310
/// let localhost = Ipv4Addr::new(127, 0, 0, 1);
311311
///
312-
/// assert_eq!(Ipv4Addr::parse_ascii(b"127.0.0.1"), Ok(localhost));
312+
/// assert_eq!(Ipv4Addr::from_bytes(b"127.0.0.1"), Ok(localhost));
313313
/// ```
314314
#[unstable(feature = "addr_parse_ascii", issue = "101035")]
315-
pub fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError> {
315+
pub fn from_bytes(b: &[u8]) -> Result<Self, AddrParseError> {
316316
// don't try to parse if too long
317317
if b.len() > 15 {
318318
Err(AddrParseError(AddrKind::Ipv4))
@@ -326,7 +326,7 @@ impl Ipv4Addr {
326326
impl FromStr for Ipv4Addr {
327327
type Err = AddrParseError;
328328
fn from_str(s: &str) -> Result<Ipv4Addr, AddrParseError> {
329-
Self::parse_ascii(s.as_bytes())
329+
Self::from_bytes(s.as_bytes())
330330
}
331331
}
332332

@@ -340,10 +340,10 @@ impl Ipv6Addr {
340340
///
341341
/// let localhost = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
342342
///
343-
/// assert_eq!(Ipv6Addr::parse_ascii(b"::1"), Ok(localhost));
343+
/// assert_eq!(Ipv6Addr::from_bytes(b"::1"), Ok(localhost));
344344
/// ```
345345
#[unstable(feature = "addr_parse_ascii", issue = "101035")]
346-
pub fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError> {
346+
pub fn from_bytes(b: &[u8]) -> Result<Self, AddrParseError> {
347347
Parser::new(b).parse_with(|p| p.read_ipv6_addr(), AddrKind::Ipv6)
348348
}
349349
}
@@ -352,7 +352,7 @@ impl Ipv6Addr {
352352
impl FromStr for Ipv6Addr {
353353
type Err = AddrParseError;
354354
fn from_str(s: &str) -> Result<Ipv6Addr, AddrParseError> {
355-
Self::parse_ascii(s.as_bytes())
355+
Self::from_bytes(s.as_bytes())
356356
}
357357
}
358358

@@ -366,10 +366,10 @@ impl SocketAddrV4 {
366366
///
367367
/// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
368368
///
369-
/// assert_eq!(SocketAddrV4::parse_ascii(b"127.0.0.1:8080"), Ok(socket));
369+
/// assert_eq!(SocketAddrV4::from_bytes(b"127.0.0.1:8080"), Ok(socket));
370370
/// ```
371371
#[unstable(feature = "addr_parse_ascii", issue = "101035")]
372-
pub fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError> {
372+
pub fn from_bytes(b: &[u8]) -> Result<Self, AddrParseError> {
373373
Parser::new(b).parse_with(|p| p.read_socket_addr_v4(), AddrKind::SocketV4)
374374
}
375375
}
@@ -378,7 +378,7 @@ impl SocketAddrV4 {
378378
impl FromStr for SocketAddrV4 {
379379
type Err = AddrParseError;
380380
fn from_str(s: &str) -> Result<SocketAddrV4, AddrParseError> {
381-
Self::parse_ascii(s.as_bytes())
381+
Self::from_bytes(s.as_bytes())
382382
}
383383
}
384384

@@ -392,10 +392,10 @@ impl SocketAddrV6 {
392392
///
393393
/// let socket = SocketAddrV6::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
394394
///
395-
/// assert_eq!(SocketAddrV6::parse_ascii(b"[2001:db8::1]:8080"), Ok(socket));
395+
/// assert_eq!(SocketAddrV6::from_bytes(b"[2001:db8::1]:8080"), Ok(socket));
396396
/// ```
397397
#[unstable(feature = "addr_parse_ascii", issue = "101035")]
398-
pub fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError> {
398+
pub fn from_bytes(b: &[u8]) -> Result<Self, AddrParseError> {
399399
Parser::new(b).parse_with(|p| p.read_socket_addr_v6(), AddrKind::SocketV6)
400400
}
401401
}
@@ -404,7 +404,7 @@ impl SocketAddrV6 {
404404
impl FromStr for SocketAddrV6 {
405405
type Err = AddrParseError;
406406
fn from_str(s: &str) -> Result<SocketAddrV6, AddrParseError> {
407-
Self::parse_ascii(s.as_bytes())
407+
Self::from_bytes(s.as_bytes())
408408
}
409409
}
410410

@@ -419,11 +419,11 @@ impl SocketAddr {
419419
/// let socket_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
420420
/// let socket_v6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8080);
421421
///
422-
/// assert_eq!(SocketAddr::parse_ascii(b"127.0.0.1:8080"), Ok(socket_v4));
423-
/// assert_eq!(SocketAddr::parse_ascii(b"[::1]:8080"), Ok(socket_v6));
422+
/// assert_eq!(SocketAddr::from_bytes(b"127.0.0.1:8080"), Ok(socket_v4));
423+
/// assert_eq!(SocketAddr::from_bytes(b"[::1]:8080"), Ok(socket_v6));
424424
/// ```
425425
#[unstable(feature = "addr_parse_ascii", issue = "101035")]
426-
pub fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError> {
426+
pub fn from_bytes(b: &[u8]) -> Result<Self, AddrParseError> {
427427
Parser::new(b).parse_with(|p| p.read_socket_addr(), AddrKind::Socket)
428428
}
429429
}
@@ -432,7 +432,7 @@ impl SocketAddr {
432432
impl FromStr for SocketAddr {
433433
type Err = AddrParseError;
434434
fn from_str(s: &str) -> Result<SocketAddr, AddrParseError> {
435-
Self::parse_ascii(s.as_bytes())
435+
Self::from_bytes(s.as_bytes())
436436
}
437437
}
438438

0 commit comments

Comments
 (0)