1
+ use crate :: bstr:: ByteStr ;
1
2
use crate :: ffi:: OsStr ;
2
3
#[ cfg( any( doc, target_os = "android" , target_os = "linux" ) ) ]
3
4
use crate :: os:: net:: linux_ext;
@@ -61,7 +62,7 @@ pub(super) fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::s
61
62
enum AddressKind < ' a > {
62
63
Unnamed ,
63
64
Pathname ( & ' a Path ) ,
64
- Abstract ( & ' a [ u8 ] ) ,
65
+ Abstract ( & ' a ByteStr ) ,
65
66
}
66
67
67
68
/// An address associated with a Unix socket.
@@ -245,7 +246,7 @@ impl SocketAddr {
245
246
{
246
247
AddressKind :: Unnamed
247
248
} else if self . addr . sun_path [ 0 ] == 0 {
248
- AddressKind :: Abstract ( & path[ 1 ..len] )
249
+ AddressKind :: Abstract ( ByteStr :: from_bytes ( & path[ 1 ..len] ) )
249
250
} else {
250
251
AddressKind :: Pathname ( OsStr :: from_bytes ( & path[ ..len - 1 ] ) . as_ref ( ) )
251
252
}
@@ -260,7 +261,7 @@ impl Sealed for SocketAddr {}
260
261
#[ stable( feature = "unix_socket_abstract" , since = "1.70.0" ) ]
261
262
impl linux_ext:: addr:: SocketAddrExt for SocketAddr {
262
263
fn as_abstract_name ( & self ) -> Option < & [ u8 ] > {
263
- if let AddressKind :: Abstract ( name) = self . address ( ) { Some ( name) } else { None }
264
+ if let AddressKind :: Abstract ( name) = self . address ( ) { Some ( name. as_bytes ( ) ) } else { None }
264
265
}
265
266
266
267
fn from_abstract_name < N > ( name : N ) -> crate :: io:: Result < Self >
@@ -295,7 +296,7 @@ impl fmt::Debug for SocketAddr {
295
296
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
296
297
match self . address ( ) {
297
298
AddressKind :: Unnamed => write ! ( fmt, "(unnamed)" ) ,
298
- AddressKind :: Abstract ( name) => write ! ( fmt, "\" {} \" (abstract)" , name . escape_ascii ( ) ) ,
299
+ AddressKind :: Abstract ( name) => write ! ( fmt, "{name:?} (abstract)" ) ,
299
300
AddressKind :: Pathname ( path) => write ! ( fmt, "{path:?} (pathname)" ) ,
300
301
}
301
302
}
0 commit comments