loosen api requirements (#8)
This commit is contained in:
parent
25ca3f4be6
commit
c453a88c99
|
@ -47,7 +47,7 @@ impl WolPacket {
|
||||||
/// ```
|
/// ```
|
||||||
/// # Panic
|
/// # Panic
|
||||||
/// Panics when input MAC is invalid (i.e. contains non-byte characters)
|
/// Panics when input MAC is invalid (i.e. contains non-byte characters)
|
||||||
pub fn from_string(data: &str, sep: char) -> WolPacket {
|
pub fn from_string<T: AsRef<str>>(data: T, sep: char) -> WolPacket {
|
||||||
WolPacket::from_bytes(&WolPacket::mac_to_byte(data, sep))
|
WolPacket::from_bytes(&WolPacket::mac_to_byte(data, sep))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +91,9 @@ impl WolPacket {
|
||||||
/// Converts string representation of MAC address (e.x. 00:01:02:03:04:05) to raw bytes.
|
/// Converts string representation of MAC address (e.x. 00:01:02:03:04:05) to raw bytes.
|
||||||
/// # Panic
|
/// # Panic
|
||||||
/// Panics when input MAC is invalid (i.e. contains non-byte characters)
|
/// Panics when input MAC is invalid (i.e. contains non-byte characters)
|
||||||
fn mac_to_byte(data: &str, sep: char) -> ArrayVec<u8, MAC_SIZE> {
|
fn mac_to_byte<T: AsRef<str>>(data: T, sep: char) -> ArrayVec<u8, MAC_SIZE> {
|
||||||
let bytes = data
|
let bytes = data
|
||||||
|
.as_ref()
|
||||||
.split(sep)
|
.split(sep)
|
||||||
.flat_map(|x| hex::decode(x).expect("Invalid mac!"))
|
.flat_map(|x| hex::decode(x).expect("Invalid mac!"))
|
||||||
.collect::<ArrayVec<u8, MAC_SIZE>>();
|
.collect::<ArrayVec<u8, MAC_SIZE>>();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user