Search results

There are no results.

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.

Static methods

new

Show source code
Hide source code
fn pub static new(address: ref Path) -> UnixAddress {
  UnixAddress(address.to_string)
}
fn pub static new(address: ref Path) -> UnixAddress

Creates a new UnixAddress from the given path or name.

Examples

Creating a UnixAddress that uses a path:

import std.net.socket (UnixAddress)

UnixAddress.new('/tmp/test.sock'.to_path)

Creating a UnixAddress that uses an unnamed address:

import std.net.socket (UnixAddress)

UnixAddress.new(''.to_path)

Creating a UnixAddress that uses an abstract address:

import std.net.socket (UnixAddress)

UnixAddress.new("\0example".to_path)

Instance methods

!=

Show source code
Hide 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 code
Hide 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 code
Hide 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 code
Hide 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 code
Hide 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 code
Hide 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 code
Hide 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

std.cmp.

Equal

impl Equal[ref UnixAddress] for UnixAddress
std.fmt.

Format

impl Format for UnixAddress
std.string.

ToString

impl ToString for UnixAddress