Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "netip"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
license = "Apache-2.0"
description = "IPv4/IPv6 network types with non-contiguous masks support"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Add to your `Cargo.toml`:

```toml
[dependencies]
netip = "0.2"
netip = "0.3"
```

### Parsing and basic operations
Expand Down Expand Up @@ -136,9 +136,9 @@ assert_eq!(mac.to_string(), "aa:bb:cc:dd:ee:ff");

## Roadmap

`netip` is on the path to a stable 1.0. Current version: **0.2.0**.
`netip` is on the path to a stable 1.0. Current version: **0.3.0**.

- **v0.3** — API cleanup: `#[must_use]`, `#[deny(missing_docs)]`
- ~~**v0.3** — API cleanup: `#[must_use]`, `#[deny(missing_docs)]`~~ ✓
- **v0.4** — Complete set algebra: `complement`, `Contiguous<T>` merge/adjacent
- **v0.5** — Testing hardening: fuzz targets, exhaustive non-contiguous edge cases
- **v0.6+** — Documentation polish, API review, CHANGELOG
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! Unlike most open-source libraries, this library is designed to support
//! non-contiguous masks.

#![deny(missing_docs)]

mod macaddr;
mod net;

Expand Down
9 changes: 9 additions & 0 deletions src/macaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl MacAddr {
/// Each parameter represents one byte of the MAC address in the standard
/// format `xx:xx:xx:xx:xx:xx`.
#[inline]
#[must_use]
pub const fn new(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8) -> MacAddr {
Self(u64::from_be_bytes([0, 0, a, b, c, d, e, f]))
}
Expand Down Expand Up @@ -109,6 +110,7 @@ impl MacAddr {
/// assert_eq!(1, MacAddr::new(0, 0, 0, 0, 0, 1).as_u64());
/// ```
#[inline]
#[must_use]
pub const fn as_u64(&self) -> u64 {
match self {
Self(addr) => *addr,
Expand All @@ -126,13 +128,15 @@ impl MacAddr {
/// assert_eq!([0x3a, 0xac, 0x26, 0x9b, 0x5b, 0xf9], mac.octets());
/// ```
#[inline]
#[must_use]
pub const fn octets(&self) -> [u8; 6] {
let [.., a, b, c, d, e, f] = self.as_u64().to_be_bytes();
[a, b, c, d, e, f]
}

/// Returns `true` if all octets are zero (`00:00:00:00:00:00`).
#[inline]
#[must_use]
pub const fn is_zero(&self) -> bool {
self.as_u64() == 0
}
Expand All @@ -141,6 +145,7 @@ impl MacAddr {
///
/// Broadcast frames are delivered to every station on the local segment.
#[inline]
#[must_use]
pub const fn is_broadcast(&self) -> bool {
self.as_u64() == 0xffff_ffff_ffff
}
Expand All @@ -159,6 +164,7 @@ impl MacAddr {
/// assert!(!MacAddr::new(0x00, 0x1a, 0x2b, 0x3c, 0x4d, 0x5e).is_multicast());
/// ```
#[inline]
#[must_use]
pub const fn is_multicast(&self) -> bool {
(self.as_u64() >> 40) & 0x01 != 0
}
Expand All @@ -177,6 +183,7 @@ impl MacAddr {
/// assert!(!MacAddr::BROADCAST.is_unicast());
/// ```
#[inline]
#[must_use]
pub const fn is_unicast(&self) -> bool {
!self.is_multicast()
}
Expand All @@ -199,6 +206,7 @@ impl MacAddr {
/// assert!(!MacAddr::new(0x00, 0x1a, 0x2b, 0x3c, 0x4d, 0x5e).is_locally_administered());
/// ```
#[inline]
#[must_use]
pub const fn is_locally_administered(&self) -> bool {
(self.as_u64() >> 40) & 0x02 != 0
}
Expand All @@ -208,6 +216,7 @@ impl MacAddr {
/// The complement of
/// [`is_locally_administered`](MacAddr::is_locally_administered).
#[inline]
#[must_use]
pub const fn is_universally_administered(&self) -> bool {
!self.is_locally_administered()
}
Expand Down
Loading
Loading