IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet IP over InfiniBand link-layer addresses and more.
Installation
Rust
[]
= "0.2"
Optional features:
# Serialization support
= { = "0.2", = ["serde"] }
# arbitrary support
= { = "0.2", = ["arbitrary"] }
# quickcheck support
= { = "0.2", = ["quickcheck"] }
# Python bindings
= { = "0.2", = ["pyo3"] }
# WebAssembly bindings
= { = "0.2", = ["wasm-bindgen"] }
Python
JavaScript/TypeScript (WASM)
Features
std(default): Standard library supportalloc: Allocation support forno_stdenvironmentsserde: Serialization/deserializationarbitrary: Fuzzing and property-based testing witharbitraryquickcheck: Property-based testing withquickcheckpyo3: Python bindingswasm-bindgen: WebAssembly/JavaScript bindings
Usage
Rust
use MacAddr;
use FromStr;
// Parse from string (supports colon, hyphen, and dot separators)
let addr = from_str.unwrap;
let addr = from_str.unwrap;
let addr = from_str.unwrap;
// Create from bytes
let addr = from_raw;
// Format conversions
println!; // 00:00:5e:00:53:01 (default: colon-separated)
println!; // 00-00-5e-00-53-01
println!; // 0000.5e00.5301
// Access bytes
let bytes: = addr.octets;
let slice: & = addr.as_bytes;
Python
# Parse from string (supports colon, hyphen, and dot separators)
=
=
=
# Create from bytes
=
# String representation
# 00:00:5e:00:53:01
# MacAddr("00:00:5e:00:53:01")
# Get bytes
=
# Comparison and hashing
=
JavaScript/TypeScript
import from 'hardware-address';
// Parse from string (supports colon, hyphen, and dot separators)
const addr = ;
const addrHyphen = ;
const addrDot = ;
// Create from bytes
const bytes = ;
const addr = ;
// Format conversions
console.log; // 00:00:5e:00:53:01
console.log; // 00-00-5e-00-53-01
console.log; // 0000.5e00.5301
// Get bytes
const bytes = addr.;
Supported Address Types
MacAddr: 6-byte IEEE 802 MAC-48/EUI-48 addressesEui64Addr: 8-byte EUI-64 addressesInfiniBandAddr: 20-byte IP over InfiniBand link-layer addresses
All types support the same API across all platforms (Rust, Python, and JavaScript).
Format Support
All address types support parsing and formatting in three standard formats:
| Format | Example |
|---|---|
| Colon-separated | 00:00:5e:00:53:01 |
| Hyphen-separated | 00-00-5e-00-53-01 |
| Dot-separated | 0000.5e00.5301 |
Pedigree
This code is inspired and modified based on Golang's mac implementation.
License
hardware-address is under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT for details.
Copyright (c) 2025 Al Liu.