Struct systemd_socket::SocketAddr

source ·
pub struct SocketAddr(/* private fields */);
Expand description

Socket address that can be an ordinary address or a systemd socket

This is the core type of this crate that abstracts possible addresses. It can be (fallibly) converted from various types of strings or deserialized with serde. After it’s created, it can be bound as TcpListener from std or even tokio or async_std if the appropriate feature is enabled.

Optional dependencies on parse_arg and serde make it trivial to use with configure_me.

Implementations§

source§

impl SocketAddr

source

pub fn from_systemd_name<T: Into<String>>(name: T) -> Result<Self, ParseError>

Creates SocketAddr from systemd name directly, without requiring systemd:// prefix.

Always fails with systemd unsupported error if systemd is not supported.

source

pub fn bind(self) -> Result<TcpListener, BindError>

Creates std::net::TcpListener

This method either binds the socket, if the address was provided or uses systemd socket if the socket name was provided.

source

pub async fn bind_tokio(self) -> Result<TcpListener, TokioBindError>

Available on crate feature tokio only.

Creates tokio::net::TcpListener

To be specific, it binds the socket or converts systemd socket to tokio 1.0 socket.

This method either binds the socket, if the address was provided or uses systemd socket if the socket name was provided.

source

pub async fn bind_tokio_0_2(self) -> Result<TcpListener, TokioBindError>

Available on crate feature tokio_0_2 only.

Creates tokio::net::TcpListener

To be specific, it binds the socket or converts systemd socket to tokio 0.2 socket.

This method either binds the socket, if the address was provided or uses systemd socket if the socket name was provided.

source

pub async fn bind_tokio_0_3(self) -> Result<TcpListener, TokioBindError>

Available on crate feature tokio_0_3 only.

Creates tokio::net::TcpListener

To be specific, it binds the socket or converts systemd socket to tokio 0.3 socket.

This method either binds the socket, if the address was provided or uses systemd socket if the socket name was provided.

source

pub async fn bind_async_std(self) -> Result<TcpListener, BindError>

Available on crate feature async-std only.

Creates async_std::net::TcpListener

To be specific, it binds the socket or converts systemd socket to async_std socket.

This method either binds the socket, if the address was provided or uses systemd socket if the socket name was provided.

Trait Implementations§

source§

impl Debug for SocketAddr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for SocketAddr

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for SocketAddr

Displays the address in format that can be parsed again.

Important: While I don’t expect this impl to change, don’t rely on it! It should be used mostly for debugging/logging.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr

source§

fn from(value: (I, u16)) -> Self

Converts to this type from the input type.
source§

impl From<SocketAddr> for SocketAddr

source§

fn from(value: SocketAddr) -> Self

Converts to this type from the input type.
source§

impl From<SocketAddrV4> for SocketAddr

source§

fn from(value: SocketAddrV4) -> Self

Converts to this type from the input type.
source§

impl From<SocketAddrV6> for SocketAddr

source§

fn from(value: SocketAddrV6) -> Self

Converts to this type from the input type.
source§

impl FromStr for SocketAddr

§

type Err = ParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl ParseArg for SocketAddr

Available on crate feature parse_arg only.
§

type Error = ParseOsStrError

Type returned in Err variant of Result when parsing fails.
source§

fn describe_type<W: Write>(writer: W) -> Result

Writes human-readable description of the type to the writer. Read more
source§

fn parse_arg(arg: &OsStr) -> Result<Self, Self::Error>

Parses the argument.
source§

fn parse_owned_arg(arg: OsString) -> Result<Self, Self::Error>

Parses the argument consuming it. Read more
source§

impl<'a> TryFrom<&'a OsStr> for SocketAddr

§

type Error = ParseOsStrError

The type returned in the event of a conversion error.
source§

fn try_from(s: &'a OsStr) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a str> for SocketAddr

§

type Error = ParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<DeserBorrowStr<'a>> for SocketAddr

Available on crate feature serde only.
§

type Error = ParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: DeserBorrowStr<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<OsString> for SocketAddr

§

type Error = ParseOsStrError

The type returned in the event of a conversion error.
source§

fn try_from(s: OsString) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<String> for SocketAddr

§

type Error = ParseError

The type returned in the event of a conversion error.
source§

fn try_from(s: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,