[−][src]Enum ichen_openprotocol::Address
A data structure holding a controller's physical address.
Variants
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.
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]
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
[src]
impl<'a> Display for Address<'a>
[src]
impl<'a> Eq for Address<'a>
[src]
impl<'a> Hash for Address<'a>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,