| Crates.io | hardware-address |
| lib.rs | hardware-address |
| version | 0.2.0 |
| created_at | 2025-01-05 06:03:08.596476+00 |
| updated_at | 2025-10-23 03:46:11.990409+00 |
| description | IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet IP over InfiniBand link-layer addresses and more |
| homepage | https://github.com/al8n/hardware-address |
| repository | https://github.com/al8n/hardware-address |
| max_upload_size | |
| id | 1504514 |
| size | 105,225 |
[dependencies]
hardware-address = "0.2"
Optional features:
# Serialization support
hardware-address = { version = "0.2", features = ["serde"] }
# arbitrary support
hardware-address = { version = "0.2", features = ["arbitrary"] }
# quickcheck support
hardware-address = { version = "0.2", features = ["quickcheck"] }
# Python bindings
hardware-address = { version = "0.2", features = ["pyo3"] }
# WebAssembly bindings
hardware-address = { version = "0.2", features = ["wasm-bindgen"] }
pip install hardware-address
npm install hardware-address
std (default): Standard library supportalloc: Allocation support for no_std environmentsserde: Serialization/deserializationarbitrary: Fuzzing and property-based testing with arbitraryquickcheck: Property-based testing with quickcheckpyo3: Python bindingswasm-bindgen: WebAssembly/JavaScript bindingsuse hardware_address::MacAddr;
use std::str::FromStr;
// Parse from string (supports colon, hyphen, and dot separators)
let addr = MacAddr::from_str("00:00:5e:00:53:01").unwrap();
let addr = MacAddr::from_str("00-00-5e-00-53-01").unwrap();
let addr = MacAddr::from_str("0000.5e00.5301").unwrap();
// Create from bytes
let addr = MacAddr::from_raw([0x00, 0x00, 0x5e, 0x00, 0x53, 0x01]);
// Format conversions
println!("{}", addr); // 00:00:5e:00:53:01 (default: colon-separated)
println!("{}", addr.to_hyphen_separated()); // 00-00-5e-00-53-01
println!("{}", addr.to_dot_separated()); // 0000.5e00.5301
// Access bytes
let bytes: [u8; 6] = addr.octets();
let slice: &[u8] = addr.as_bytes();
from hardware_address import MacAddr
# Parse from string (supports colon, hyphen, and dot separators)
addr = MacAddr.parse("00:00:5e:00:53:01")
addr = MacAddr.parse("00-00-5e-00-53-01")
addr = MacAddr.parse("0000.5e00.5301")
# Create from bytes
addr = MacAddr(b"\x00\x00\x5e\x00\x53\x01")
# String representation
print(str(addr)) # 00:00:5e:00:53:01
print(repr(addr)) # MacAddr("00:00:5e:00:53:01")
# Get bytes
data = bytes(addr)
# Comparison and hashing
if addr1 == addr2:
print("Addresses are equal")
my_dict = {addr: "device1"}
import { MacAddr } from 'hardware-address';
// Parse from string (supports colon, hyphen, and dot separators)
const addr = MacAddr.parse("00:00:5e:00:53:01");
const addrHyphen = MacAddr.parse("00-00-5e-00-53-01");
const addrDot = MacAddr.parse("0000.5e00.5301");
// Create from bytes
const bytes = new Uint8Array([0x00, 0x00, 0x5e, 0x00, 0x53, 0x01]);
const addr = MacAddr.fromBytes(bytes);
// Format conversions
console.log(addr.toString()); // 00:00:5e:00:53:01
console.log(addr.toHyphenSeparated()); // 00-00-5e-00-53-01
console.log(addr.toDotSeparated()); // 0000.5e00.5301
// Get bytes
const bytes = addr.toBytes();
MacAddr: 6-byte IEEE 802 MAC-48/EUI-48 addressesEui64Addr: 8-byte EUI-64 addressesInfiniBandAddr: 20-byte IP over InfiniBand link-layer addressesAll types support the same API across all platforms (Rust, Python, and JavaScript).
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 |
This code is inspired and modified based on Golang's mac implementation.
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.