Enum Address

Source
pub enum Address<'a> {
    Unknown,
    IPv4(Ipv4Addr, NonZeroU16),
    ComPort(NonZeroU8),
    TtyDevice(TextID<'a>),
}
Expand description

A data structure holding a controller’s physical address.

Variants§

§

Unknown

Address unknown.

§

IPv4(Ipv4Addr, NonZeroU16)

An IP v.4 address plus port.

§

ComPort(NonZeroU8)

A Windows COM port.

§

TtyDevice(TextID<'a>)

A UNIX-style tty serial port device.

Implementations§

Source§

impl<'a> Address<'a>

Source

pub fn new_ipv4(addr: &str, port: u16) -> Result<Self, String>

Create a new Address::IPv4 from an IP address string and port number.

The IP address cannot be unspecified (e.g. 0.0.0.0). The IP port cannot be zero.

§Errors

Returns Err(String) if:

  • The IP address string is invalid,
  • The IP address is unspecified (e.g. 0.0.0.0),
  • The IP port is zero.
§Error Examples
assert_eq!(Err("invalid IP address: [hello]".into()), Address::new_ipv4("hello", 123));
assert_eq!(Err("IP port cannot be zero".into()), Address::new_ipv4("1.02.003.004", 0));
assert_eq!(Err("invalid null IP address".into()), Address::new_ipv4("0.00.000.0", 123));
§Examples
assert_eq!(
    Address::IPv4(Ipv4Addr::from_str("1.2.3.4").unwrap(), NonZeroU16::new(5).unwrap()),
    Address::new_ipv4("1.02.003.004", 5)?
);
Source

pub fn new_com_port(port: u8) -> Result<Self, String>

Create a new Address::ComPort from a Windows serial port number.

The COM port number cannot be zero.

§Errors

Returns Err(String) if the COM port number is zero.

§Error Examples
assert_eq!(Err("COM port cannot be zero".into()), Address::new_com_port(0));
§Examples
assert_eq!(
    Address::ComPort(NonZeroU8::new(5).unwrap()),
    Address::new_com_port(5)?
);
Source

pub fn new_tty_device(device: &'a str) -> Result<Self, String>

Create a new Address::TtyDevice from a UNIX-style tty device name.

The device name should start with tty.

§Errors

Returns Err(String) if the device name is not valid for a tty.

§Error Examples
assert_eq!(Err("invalid tty device: [hello]".into()), Address::new_tty_device("hello"));
§Examples
assert_eq!(
    Address::TtyDevice(TextID::new("ttyHello").unwrap()),
    Address::new_tty_device("ttyHello")?
);

Trait Implementations§

Source§

impl<'a> Clone for Address<'a>

Source§

fn clone(&self) -> Address<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Address<'a>

Source§

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

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

impl<'a, 'de: 'a> Deserialize<'de> for Address<'a>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

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

impl<'a> Display for Address<'a>

Source§

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

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

impl<'a> Hash for Address<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Address<'a>

Source§

fn eq(&self, other: &Address<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Address<'_>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

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

Source§

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

Parse a text string into an Address.

§Errors

Returns Err(String) if the input string is not recognized as a valid address.

§Error Examples
// The following should error because port cannot be zero if IP address is not zero
assert_eq!(
    Err("IP port cannot be zero".into()),
    Address::try_from("1.02.003.004:0")
);

// The following should error because port must be zero if IP address is zero
assert_eq!(
    Err("null IP must have zero port number".into()),
    Address::try_from("0.0.0.0:123")
);
§Examples
assert_eq!(
    Address::IPv4(Ipv4Addr::from_str("1.2.3.4").unwrap(), NonZeroU16::new(5).unwrap()),
    Address::try_from("1.02.003.004:05")?
);

// 0.0.0.0:0 is OK because both IP address and port are zero
assert_eq!(Address::Unknown, Address::try_from("0.0.0.0:0")?);

assert_eq!(
    Address::ComPort(NonZeroU8::new(123).unwrap()),
    Address::try_from("COM123")?
);

assert_eq!(
    Address::TtyDevice(TextID::new("ttyABC").unwrap()),
    Address::try_from("ttyABC")?
);
Source§

type Error = String

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

impl<'a> Eq for Address<'a>

Source§

impl<'a> StructuralPartialEq for Address<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Address<'a>

§

impl<'a> RefUnwindSafe for Address<'a>

§

impl<'a> Send for Address<'a>

§

impl<'a> Sync for Address<'a>

§

impl<'a> Unpin for Address<'a>

§

impl<'a> UnwindSafe for Address<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

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.
Source§

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