Enum AutoName

Source
pub enum AutoName<'a> {
    Auto(&'a str),
    HostPort(&'a str, u16),
    HostDefaultPort(&'a str),
    Service(&'a str),
    IpAddr(IpAddr),
    SocketAddr(SocketAddr),
}
Expand description

A name type that can be read from config

The core idea of AutoName is that for service with default port 80 (HTTP) we treat names the following way:

  • example.org → A record example.org, port 80
  • example.org:8080 → A record example.org, port 8080
  • _service._proto.example.org → SRV record, and port from the record
  • 127.0.0.1 → IP used directly, port 80
  • 127.0.0.1:8080 → IP/port used directly
  • 2001:db8::2:1 → IPv6 address (note: no brackets)
  • [2001:db8::2:1]:1235 → IPv6 address and port (note: square brackets)

This works by wrapping the string read from configuration file into AutoName::Auto and using it in Router. You might override things via configuration specific things, for example in yaml you might want to write:

addresses:
- !Srv myservice.query.consul

… And convert it into Service("myservice.query.consul") which will be resolved using SRV record (or similar mechanism) instead of using hostname (i.e. standard expects using _service._proto prefix but does not requires that).

Variants§

§

Auto(&'a str)

Auto-determine how to treat the name

§

HostPort(&'a str, u16)

Resolve host and attach specified port

§

HostDefaultPort(&'a str)

Resolve host and attach default port to it

§

Service(&'a str)

Use service name and port resolved using SRV record or similar

§

IpAddr(IpAddr)

A bare IP used directly as a host

§

SocketAddr(SocketAddr)

A bare socket address used directly as a service address

Trait Implementations§

Source§

impl<'a> Debug for AutoName<'a>

Source§

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

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

impl<'a, T: AsRef<str> + 'a> From<&'a T> for AutoName<'a>

Source§

fn from(val: &'a T) -> AutoName<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for AutoName<'a>

Source§

fn from(val: &'a str) -> AutoName<'a>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for AutoName<'a>

§

impl<'a> RefUnwindSafe for AutoName<'a>

§

impl<'a> Send for AutoName<'a>

§

impl<'a> Sync for AutoName<'a>

§

impl<'a> Unpin for AutoName<'a>

§

impl<'a> UnwindSafe for AutoName<'a>

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.