Crates.io | eui48 |
lib.rs | eui48 |
version | 1.1.0 |
source | src |
created_at | 2016-02-13 01:20:16.663355 |
updated_at | 2020-08-24 18:17:26.916772 |
description | A library to generate and parse IEEE EUI-48 and EUI-64, also known as MAC-48 media access control addresses. The IEEE claims trademarks on the names EUI-48 and EUI-64, in which EUI is an abbreviation for Extended Unique Identifier. |
homepage | https://github.com/abaumhauer/eui48 |
repository | https://github.com/abaumhauer/eui48 |
max_upload_size | |
id | 4160 |
size | 52,102 |
A Rust library to represent and parse IEEE EUI-48 also known as MAC-48 media access control addresses. The IEEE claims trademarks on the names EUI-48 and EUI-64, in which EUI is an abbreviation for Extended Unique Identifier.
Add this to your Cargo.toml
:
[dependencies]
eui48 = "1.0.1"
and this to your crate root:
extern crate eui48;
To create a new MAC address and print it out in canonical form:
extern crate eui48;
use eui48::{MacAddress, Eui48};
fn main() {
let eui: Eui48 = [ 0x12, 0x34, 0x56, 0xAB, 0xCD, 0xEF ];
let mac = MacAddress::new( eui );
println!("{}", mac.to_canonical());
println!("{}", mac.to_hex_string());
println!("{}", mac.to_dot_string());
println!("{}", mac.to_hexadecimal());
println!("{}", mac.to_interfaceid());
println!("{}", mac.to_link_local());
let mac = MacAddress::parse_str( "01-02-03-0A-0b-0f" ).expect("Parse error {}");
let mac = MacAddress::parse_str( "01:02:03:0A:0b:0f" ).expect("Parse error {}");
let mac = MacAddress::parse_str( "0102.030A.0b0f" ).expect("Parse error {}");
let mac = MacAddress::parse_str( "0x1234567890ab" ).expect("Parse error {}");
}
01-02-03-04-05-06
unless a compile time feature disp_hexstring
is enabled, then the default format is of the form 01:02:03:04:05:06
.Version 1.0.0 and above allows a more flexible parsing of MAC address strings, compliments of Stan Drozd:
When using serde
to serialize a MAC address the address is stored as a formatted string. This fits well for text-based protocols like JSON but creates overhead for binary serialization. The overhead gets even bigger when the string is deserialized again, as a full-grown parser is needed instead of reading raw bytes. To reduce this overhead use the serde_bytes
feature when serializing and deserializing MAC addresses to binary protocols.
NOTE: serde_bytes
and serde_json
are mutually exclusive!