[][src]Enum ichen_openprotocol::Address

pub enum Address<'a> {
    Unknown,
    IPv4(Ipv4AddrNonZeroU16),
    ComPort(NonZeroU8),
    TtyDevice(TextID<'a>),
}

A data structure holding a controller's physical address.

Variants

Unknown

Address unknown.

An IP v.4 address plus port.

ComPort(NonZeroU8)

A Windows COM port.

TtyDevice(TextID<'a>)

A UNIX-style tty serial port device.

Methods

impl<'a> Address<'a>[src]

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

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)?
);

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

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)?
);

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

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

impl<'a> Clone for Address<'a>[src]

impl<'a> Debug for Address<'a>[src]

impl<'a, 'de: 'a> Deserialize<'de> for Address<'a>[src]

impl<'a> Display for Address<'a>[src]

impl<'a> Eq for Address<'a>[src]

impl<'a> Hash for Address<'a>[src]

impl<'a> PartialEq<Address<'a>> for Address<'a>[src]

impl<'_> Serialize for Address<'_>[src]

impl<'a> StructuralEq for Address<'a>[src]

impl<'a> StructuralPartialEq for Address<'a>[src]

impl<'a> TryFrom<&'a str> for Address<'a>[src]

type Error = String

The type returned in the event of a conversion error.

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

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")?
);

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,