std.net.socket.UnixAddress
class pub UnixAddress
A Unix domain socket address.
Fields
address
let pub @address: String
The path or name of the address.
This is a String
since using a Path
does not make sense for abstract
and unnamed addresses.
Instance methods
!=
Show source codeHide source code
fn pub !=(other: T) -> Bool {
(self == other).false?
}
fn pub !=(other: T) -> Bool
Returns true
if self
and the given object are not equal to each other.
==
Show source codeHide source code
fn pub ==(other: ref UnixAddress) -> Bool {
@address == other.address
}
fn pub ==(other: ref UnixAddress) -> Bool
Returns true
if self
and other
are the same socket addresses.
Examples
Comparing two UnixAddress
objects:
import std.net.socket (UnixAddress)
UnixAddress.new('a.sock'.to_path) == UnixAddress.new('a.sock'.to_path) # => true
UnixAddress.new('a.sock'.to_path) == UnixAddress.new('b.sock'.to_path) # => false
abstract?
Show source codeHide source code
fn pub abstract? -> Bool {
@address.starts_with?('\0')
}
fn pub abstract? -> Bool
Returns true
if self
is an abstract address.
Examples
Checking if an address is abstract:
import std.net.socket (UnixAddress)
UnixAddress.new('/tmp/test.sock'.to_path).abstract? # => false
UnixAddress.new("\0example-address".to_path).abstract? # => true
fmt
Show source codeHide source code
fn pub fmt(formatter: mut Formatter) {
let write = if abstract? {
'@${@address.slice(start: 1, size: @address.size - 1)}'
} else if unnamed? {
'unnamed'
} else {
@address
}
formatter.write(write)
}
fn pub fmt(formatter: mut Formatter)
Formats self
in a human-readable format for debugging purposes.
to_path
Show source codeHide source code
fn pub to_path -> Option[Path] {
if unnamed? or abstract? {
Option.None
} else {
Option.Some(@address.to_path)
}
}
fn pub to_path -> Option[Path]
Returns the path of this address.
If the address is unnamed or an abstract address, None is returned.
to_string
Show source codeHide source code
fn pub to_string -> String {
@address
}
fn pub to_string -> String
Returns the address name or path as a String
.
Examples
Converting a UnixAddress
to a String
:
import std.net.socket (UnixAddress)
UnixAddress.new('/tmp/test.sock'.to_path).to_string # => '/tmp/test.sock'
UnixAddress.new("\0example".to_path).to_string # => "\0example"
unnamed?
Show source codeHide source code
fn pub unnamed? -> Bool {
@address.empty?
}
fn pub unnamed? -> Bool
Returns true
if self
is an unnamed address.
Examples
Checking if an address is unnamed:
import std.net.socket (UnixAddress)
UnixAddress.new('/tmp/test.sock'.to_path).unnamed? # => false
UnixAddress.new(''.to_path).unnamed? # => true
Implemented traits
Equal
impl Equal[ref UnixAddress] for UnixAddress
Format
impl Format for UnixAddress
ToString
impl ToString for UnixAddress