| 1 | // Copyright (c) 2014-2016 Robert Clipsham <[email protected]> |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 8 | |
| 9 | #[cfg(feature = "std")] |
| 10 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#; |
| 11 | |
| 12 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/; |
| 13 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 14 | |
| 15 | #[cfg(feature = "serde")] |
| 16 | use serderust-analyzer cargo serde 1.0.229 crate/::{derust-analyzer cargo serde_core 1.0.229 de/, Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#}; |
| 17 | |
| 18 | /// The number of bytes in an ethernet (MAC) address. |
| 19 | pub const ETHER_ADDR_LENrust-analyzer cargo pnet_base 0.35.0 macaddr/ETHER_ADDR_LEN.: usize = 6; |
| 20 | |
| 21 | /// Structure of a 48-bit Ethernet address. |
| 22 | type EtherAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/EtherAddr# = [u8; ETHER_ADDR_LENrust-analyzer cargo pnet_base 0.35.0 macaddr/ETHER_ADDR_LEN.]; |
| 23 | |
| 24 | const LOCAL_ADDR_BITrust-analyzer cargo pnet_base 0.35.0 macaddr/LOCAL_ADDR_BIT.: u8 = 0x02; |
| 25 | const MULTICAST_ADDR_BITrust-analyzer cargo pnet_base 0.35.0 macaddr/MULTICAST_ADDR_BIT.: u8 = 0x01; |
| 26 | |
| 27 | /// A MAC address. |
| 28 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:)] |
| 29 | pub struct MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(pub u8, pub u8, pub u8, pub u8, pub u8, pub u8); |
| 30 | |
| 31 | impl MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 32 | /// Construct a new `MacAddr` instance. |
| 33 | pub fn newrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]new().(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8) -> MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 34 | MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(a, b, c, d, e, f) |
| 35 | } |
| 36 | |
| 37 | /// Construct an all-zero `MacAddr` instance. |
| 38 | pub fn zerorust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]zero().() -> MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 39 | Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][Default]default().() |
| 40 | } |
| 41 | |
| 42 | /// Construct a broadcast `MacAddr` instance. |
| 43 | pub fn broadcastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]broadcast().() -> MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 44 | [0xff; ETHER_ADDR_LENrust-analyzer cargo pnet_base 0.35.0 macaddr/ETHER_ADDR_LEN.].intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 45 | } |
| 46 | |
| 47 | /// Returns true if a `MacAddr` is an all-zero address. |
| 48 | pub fn is_zerorust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_zero().(&self) -> bool { |
| 49 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq().Selfrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]::zerorust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]zero().() |
| 50 | } |
| 51 | |
| 52 | /// Returns true if the MacAddr is a universally administered addresses (UAA). |
| 53 | pub fn is_universalrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_universal().(&self) -> bool { |
| 54 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_localrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_local().() |
| 55 | } |
| 56 | |
| 57 | /// Returns true if the MacAddr is a locally administered addresses (LAA). |
| 58 | pub fn is_localrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_local().(&self) -> bool { |
| 59 | (self.0rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().LOCAL_ADDR_BITrust-analyzer cargo pnet_base 0.35.0 macaddr/LOCAL_ADDR_BIT.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().LOCAL_ADDR_BITrust-analyzer cargo pnet_base 0.35.0 macaddr/LOCAL_ADDR_BIT. |
| 60 | } |
| 61 | |
| 62 | /// Returns true if the MacAddr is a unicast address. |
| 63 | pub fn is_unicastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_unicast().(&self) -> bool { |
| 64 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_multicastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_multicast().() |
| 65 | } |
| 66 | |
| 67 | /// Returns true if the MacAddr is a multicast address. |
| 68 | pub fn is_multicastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_multicast().(&self) -> bool { |
| 69 | (self.0rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().MULTICAST_ADDR_BITrust-analyzer cargo pnet_base 0.35.0 macaddr/MULTICAST_ADDR_BIT.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().MULTICAST_ADDR_BITrust-analyzer cargo pnet_base 0.35.0 macaddr/MULTICAST_ADDR_BIT. |
| 70 | } |
| 71 | |
| 72 | /// Returns true if the MacAddr is a broadcast address. |
| 73 | pub fn is_broadcastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_broadcast().(&self) -> bool { |
| 74 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq().Selfrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]::broadcastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]broadcast().() |
| 75 | } |
| 76 | |
| 77 | /// Returns the six eight-bit integers that make up this address |
| 78 | pub fn octetsrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]octets().(&self) -> [u8; 6] { |
| 79 | [self.0rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#0., self.1rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#1., self.2rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#2., self.3rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#3., self.4rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#4., self.5rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#5.] |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<EtherAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/EtherAddr#> for MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 84 | fn fromrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`From<[u8; ETHER_ADDR_LEN]>`]from().(addr: EtherAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/EtherAddr#) -> MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 85 | MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(addr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., addr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., addr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., addr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., addr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., addr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#> for EtherAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/EtherAddr# { |
| 90 | fn fromrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[`[u8; ETHER_ADDR_LEN]`][`From<MacAddr>`]from().(addr: MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#) -> Selfrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[`[u8; ETHER_ADDR_LEN]`][`From<MacAddr>`] { |
| 91 | [addr.0rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#0., addr.1rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#1., addr.2rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#2., addr.3rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#3., addr.4rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#4., addr.5rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#5.] |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<EtherAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/EtherAddr#> for MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 96 | fn eqrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<[u8; ETHER_ADDR_LEN]>`]eq().(&self, other: &EtherAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/EtherAddr#) -> bool { |
| 97 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`PartialEq<Self>`]eq().MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::fromrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`From<[u8; ETHER_ADDR_LEN]>`]from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 102 | fn fmtrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][Display]fmt().(&self, fmt: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 103 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 104 | fmt, |
| 105 | "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", |
| 106 | self.0rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#0., self.1rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#1., self.2rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#2., self.3rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#3., self.4rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#4., self.5rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#5. |
| 107 | ) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | #[cfg(feature = "serde")] |
| 112 | impl Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 113 | /// Serializes the MAC address. |
| 114 | /// |
| 115 | /// It serializes either to a string or its binary representation, depending on what the format |
| 116 | /// prefers. |
| 117 | fn serializerust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][Serialize]serialize().<S: Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#> { |
| 118 | if serializer.is_human_readablerust-analyzer cargo serde_core 1.0.229 ser/Serializer#is_human_readable().() { |
| 119 | serializer.collect_strrust-analyzer cargo serde_core 1.0.229 ser/Serializer#collect_str().(self) |
| 120 | } else { |
| 121 | serializer.serialize_bytesrust-analyzer cargo serde_core 1.0.229 ser/Serializer#serialize_bytes().(&[self.0rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#0., self.1rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#1., self.2rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#2., self.3rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#3., self.4rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#4., self.5rust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#5.]) |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | #[cfg(feature = "serde")] |
| 127 | impl<'de> Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 128 | /// Deserializes the MAC address. |
| 129 | /// |
| 130 | /// It deserializes it from either a byte array (of size 6) or a string. If the format is |
| 131 | /// self-descriptive (like JSON or MessagePack), it auto-detects it. If not, it obeys the |
| 132 | /// human-readable property of the deserializer. |
| 133 | fn deserializerust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`Deserialize<'de>`]deserialize().<D: Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> { |
| 134 | struct MacAddrVisitorrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddrVisitor#; |
| 135 | impl<'de> derust-analyzer cargo serde_core 1.0.229 de/::Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#<'de> for MacAddrVisitorrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddrVisitor# { |
| 136 | type Valuerust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddrVisitor][`Visitor<'de>`]Value# = MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#; |
| 137 | |
| 138 | fn visit_strrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddrVisitor][`Visitor<'de>`]visit_str().<E: derust-analyzer cargo serde_core 1.0.229 de/::Errorrust-analyzer cargo serde_core 1.0.229 de/Error#>(self, value: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#, E> { |
| 139 | value.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| E::customrust-analyzer cargo serde_core 1.0.229 de/Error#custom().(err)) |
| 140 | } |
| 141 | |
| 142 | fn visit_bytesrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddrVisitor][`Visitor<'de>`]visit_bytes().<E: derust-analyzer cargo serde_core 1.0.229 de/::Errorrust-analyzer cargo serde_core 1.0.229 de/Error#>(self, v: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#, E> { |
| 143 | if v.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().6 { |
| 144 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::newrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]new().(v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)) |
| 145 | } else { |
| 146 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(E::invalid_lengthrust-analyzer cargo serde_core 1.0.229 de/Error#invalid_length().(v.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), &self)) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | fn expectingrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddrVisitor][`Visitor<'de>`]expecting().(&self, formatter: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 151 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 152 | formatter, |
| 153 | "either a string representation of a MAC address or 6-element byte array" |
| 154 | ) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Decide what hint to provide to the deserializer based on if it is human readable or not |
| 159 | if deserializer.is_human_readablerust-analyzer cargo serde_core 1.0.229 de/Deserializer#is_human_readable().() { |
| 160 | deserializer.deserialize_strrust-analyzer cargo serde_core 1.0.229 de/Deserializer#deserialize_str().(MacAddrVisitorrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddrVisitor#) |
| 161 | } else { |
| 162 | deserializer.deserialize_bytesrust-analyzer cargo serde_core 1.0.229 de/Deserializer#deserialize_bytes().(MacAddrVisitorrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddrVisitor#) |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 168 | fn fmtrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 169 | fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][Display]fmt().(self, fmt) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /// Represents an error which occurred whilst parsing a MAC address. |
| 174 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 175 | pub enum ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr# { |
| 176 | /// The MAC address has too many components, eg. 00:11:22:33:44:55:66. |
| 177 | TooManyComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooManyComponents#, |
| 178 | /// The MAC address has too few components, eg. 00:11. |
| 179 | TooFewComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooFewComponents#, |
| 180 | /// One of the components contains an invalid value, eg. 00:GG:22:33:44:55. |
| 181 | InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#, |
| 182 | } |
| 183 | |
| 184 | #[cfg(feature = "std")] |
| 185 | impl Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr# {} |
| 186 | |
| 187 | impl ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr# { |
| 188 | fn descriptionrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[ParseMacAddrErr]description().(&self) -> &str { |
| 189 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 190 | ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::TooManyComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooManyComponents# => "Too many components in a MAC address string", |
| 191 | ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::TooFewComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooFewComponents# => "Too few components in a MAC address string", |
| 192 | ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent# => "Invalid component in a MAC address string", |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr# { |
| 198 | fn fmtrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[ParseMacAddrErr][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 199 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.descriptionrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[ParseMacAddrErr]description().()) |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr# { |
| 204 | type Errrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][FromStr]Err# = ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#; |
| 205 | fn from_strrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#, ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#> { |
| 206 | let mut parts = [0u8; 6]; |
| 207 | let splits = s.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(':'); |
| 208 | let mut i = 0; |
| 209 | for split in splits { |
| 210 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().6 { |
| 211 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::TooManyComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooManyComponents#); |
| 212 | } |
| 213 | match u8::from_str_radixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]from_str_radix().(split, 16) { |
| 214 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(b) if split.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 => parts[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = b, |
| 215 | _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#), |
| 216 | } |
| 217 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 218 | } |
| 219 | |
| 220 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().6 { |
| 221 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#( |
| 222 | parts[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., parts[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., parts[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., parts[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., parts[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., parts[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., |
| 223 | )) |
| 224 | } else { |
| 225 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::TooFewComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooFewComponents#) |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | #[cfg(test)] |
| 231 | mod testsrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/ { |
| 232 | use superrust-analyzer cargo pnet_base 0.35.0 macaddr/::*; |
| 233 | |
| 234 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 235 | fn mac_addr_from_strrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/mac_addr_from_str().() { |
| 236 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("00:00:00:00:00:00".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::zerorust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]zero().())); |
| 237 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("ff:ff:ff:ff:ff:ff".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::broadcastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]broadcast().())); |
| 238 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 239 | "12:34:56:78:90:ab".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), |
| 240 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(0x12, 0x34, 0x56, 0x78, 0x90, 0xAB)) |
| 241 | ); |
| 242 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 243 | "::::::".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 244 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#) |
| 245 | ); |
| 246 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 247 | "0::::::".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 248 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#) |
| 249 | ); |
| 250 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 251 | "::::0::".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 252 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#) |
| 253 | ); |
| 254 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 255 | "12:34:56:78".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 256 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::TooFewComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooFewComponents#) |
| 257 | ); |
| 258 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 259 | "12:34:56:78:".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 260 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#) |
| 261 | ); |
| 262 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 263 | "12:34:56:78:90".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 264 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::TooFewComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooFewComponents#) |
| 265 | ); |
| 266 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 267 | "12:34:56:78:90:".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 268 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#) |
| 269 | ); |
| 270 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 271 | "12:34:56:78:90:00:00".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 272 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::TooManyComponentsrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#TooManyComponents#) |
| 273 | ); |
| 274 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 275 | "xx:xx:xx:xx:xx:xx".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>(), |
| 276 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseMacAddrErrrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#::InvalidComponentrust-analyzer cargo pnet_base 0.35.0 macaddr/ParseMacAddrErr#InvalidComponent#) |
| 277 | ); |
| 278 | } |
| 279 | |
| 280 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 281 | fn str_from_mac_addrrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/str_from_mac_addr().() { |
| 282 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::zerorust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]zero().()), "00:00:00:00:00:00"); |
| 283 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::broadcastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]broadcast().()), "ff:ff:ff:ff:ff:ff"); |
| 284 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 285 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(0x12, 0x34, 0x56, 0x78, 0x09, 0xAB)), |
| 286 | "12:34:56:78:09:ab" |
| 287 | ); |
| 288 | } |
| 289 | |
| 290 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 291 | fn fixed_size_slice_from_mac_addrrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/fixed_size_slice_from_mac_addr().() { |
| 292 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 293 | MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(0x00, 0x01, 0x02, 0x03, 0x04, 0x05).octetsrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]octets().(), |
| 294 | [0x00, 0x01, 0x02, 0x03, 0x04, 0x05] |
| 295 | ); |
| 296 | } |
| 297 | |
| 298 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 299 | fn type_of_addrrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/type_of_addr().() { |
| 300 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::zerorust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]zero().().is_zerorust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_zero().()); |
| 301 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::broadcastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]broadcast().().is_broadcastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_broadcast().()); |
| 302 | |
| 303 | let mac = MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(0x12, 0x34, 0x56, 0x78, 0x90, 0xAB); |
| 304 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(mac.is_localrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_local().()); |
| 305 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(mac.is_unicastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_unicast().()); |
| 306 | |
| 307 | let mac = MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(0xac, 0x87, 0xa3, 0x07, 0x32, 0xb8); |
| 308 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(mac.is_universalrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_universal().()); |
| 309 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(mac.is_unicastrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]is_unicast().()); |
| 310 | } |
| 311 | |
| 312 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 313 | fn conversionrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/conversion().() { |
| 314 | let mac = MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#(0x12, 0x34, 0x56, 0x78, 0x90, 0xAB); |
| 315 | let addr = [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB]; |
| 316 | |
| 317 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(mac, MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::fromrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr][`From<[u8; ETHER_ADDR_LEN]>`]from().(addr)); |
| 318 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(addr, EtherAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/EtherAddr#::fromrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[`[u8; ETHER_ADDR_LEN]`][`From<MacAddr>`]from().(mac)); |
| 319 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(mac == addr); |
| 320 | } |
| 321 | |
| 322 | #[cfg(feature = "serde")] |
| 323 | mod serderust-analyzer cargo pnet_base 0.35.0 macaddr/tests/serde/ { |
| 324 | extern crate serde_testrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/serde/serde_test/; |
| 325 | use selfrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/serde/::serde_testrust-analyzer cargo serde_test 1.0.177 crate/::{ |
| 326 | assert_de_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens()., assert_de_tokens_errorrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens_error()., assert_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_tokens()., Compactrust-analyzer cargo serde_test 1.0.177 configure/Compact#, Configurerust-analyzer cargo serde_test 1.0.177 configure/Configure#, Readablerust-analyzer cargo serde_test 1.0.177 configure/Readable#, |
| 327 | Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#, |
| 328 | }; |
| 329 | use superrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/::*; |
| 330 | |
| 331 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 332 | fn stringrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/serde/string().() { |
| 333 | let mac = MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::newrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]new().(0x11, 0x22, 0x33, 0x44, 0x55, 0x66); |
| 334 | assert_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_tokens().(&mac.readablerust-analyzer cargo serde_test 1.0.177 configure/Configure#readable().(), &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Strrust-analyzer cargo serde_test 1.0.177 token/Token#Str#("11:22:33:44:55:66")]); |
| 335 | assert_de_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens().(&mac.readablerust-analyzer cargo serde_test 1.0.177 configure/Configure#readable().(), &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Stringrust-analyzer cargo serde_test 1.0.177 token/Token#String#("11:22:33:44:55:66")]); |
| 336 | assert_de_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens().(&mac.readablerust-analyzer cargo serde_test 1.0.177 configure/Configure#readable().(), &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::BorrowedStrrust-analyzer cargo serde_test 1.0.177 token/Token#BorrowedStr#("11:22:33:44:55:66")]); |
| 337 | assert_de_tokens_errorrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens_error().::<Readablerust-analyzer cargo serde_test 1.0.177 configure/Readable#<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>>( |
| 338 | &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Strrust-analyzer cargo serde_test 1.0.177 token/Token#Str#("not an address")], |
| 339 | "Invalid component in a MAC address string", |
| 340 | ); |
| 341 | // It still can detect bytes if provided |
| 342 | assert_de_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens().( |
| 343 | &mac.readablerust-analyzer cargo serde_test 1.0.177 configure/Configure#readable().(), |
| 344 | &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Bytesrust-analyzer cargo serde_test 1.0.177 token/Token#Bytes#(&[0x11, 0x22, 0x33, 0x44, 0x55, 0x66])], |
| 345 | ); |
| 346 | } |
| 347 | |
| 348 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 349 | fn bytesrust-analyzer cargo pnet_base 0.35.0 macaddr/tests/serde/bytes().() { |
| 350 | let mac = MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#::newrust-analyzer cargo pnet_base 0.35.0 macaddr/impl#[MacAddr]new().(0x11, 0x22, 0x33, 0x44, 0x55, 0x66); |
| 351 | assert_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_tokens().( |
| 352 | &mac.compactrust-analyzer cargo serde_test 1.0.177 configure/Configure#compact().(), |
| 353 | &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Bytesrust-analyzer cargo serde_test 1.0.177 token/Token#Bytes#(&[0x11, 0x22, 0x33, 0x44, 0x55, 0x66])], |
| 354 | ); |
| 355 | assert_de_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens().( |
| 356 | &mac.compactrust-analyzer cargo serde_test 1.0.177 configure/Configure#compact().(), |
| 357 | &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::BorrowedBytesrust-analyzer cargo serde_test 1.0.177 token/Token#BorrowedBytes#(&[0x11, 0x22, 0x33, 0x44, 0x55, 0x66])], |
| 358 | ); |
| 359 | let err = "invalid length 2, expected either a string representation of a MAC address or 6-element byte array"; |
| 360 | assert_de_tokens_errorrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens_error().::<Compactrust-analyzer cargo serde_test 1.0.177 configure/Compact#<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>>(&[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Bytesrust-analyzer cargo serde_test 1.0.177 token/Token#Bytes#(&[0x11, 0x33])], err); |
| 361 | let err = "invalid length 7, expected either a string representation of a MAC address or 6-element byte array"; |
| 362 | assert_de_tokens_errorrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens_error().::<Compactrust-analyzer cargo serde_test 1.0.177 configure/Compact#<MacAddrrust-analyzer cargo pnet_base 0.35.0 macaddr/MacAddr#>>( |
| 363 | &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Bytesrust-analyzer cargo serde_test 1.0.177 token/Token#Bytes#(&[0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77])], |
| 364 | err, |
| 365 | ); |
| 366 | // Still can decode string in the compact mode |
| 367 | assert_de_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_de_tokens().(&mac.compactrust-analyzer cargo serde_test 1.0.177 configure/Configure#compact().(), &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::Strrust-analyzer cargo serde_test 1.0.177 token/Token#Str#("11:22:33:44:55:66")]); |
| 368 | } |
| 369 | } |
| 370 | } |