From a287c65325bcc6fcb202ead35c26e9f9419b7c02 Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Tue, 16 Dec 2025 17:17:42 +0800 Subject: [PATCH] feat: add reference for IpCidr and IpNet Currently IpCidr and IpNet will return the first_address/address directly, it's ok, but when if we want to use IpCidr as radix trie key, many radix trie implement require the key type can borrowed as &[u8], however we can't return a the local variable(the IpAddr) reference. With this PR we can borrow the IpAddr in IpCidr/IpNet directly to avoid this problem --- src/cidr/direct.rs | 5 +++++ src/inet/direct.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/cidr/direct.rs b/src/cidr/direct.rs index be68fe7..bf07f6d 100644 --- a/src/cidr/direct.rs +++ b/src/cidr/direct.rs @@ -119,6 +119,11 @@ macro_rules! impl_cidr_for { self.address } + /// the reference about first address in the network as plain address + pub const fn first_address_ref(&self) -> &$addr { + &self.address + } + /// first address in the network pub const fn first(&self) -> $inet { $inet { diff --git a/src/inet/direct.rs b/src/inet/direct.rs index 0af3525..37471cb 100644 --- a/src/inet/direct.rs +++ b/src/inet/direct.rs @@ -202,6 +202,11 @@ macro_rules! impl_inet_for { self.address } + /// the reference about host + pub const fn address_ref(&self) -> &$addr { + &self.address + } + /// first address in the network as plain address pub const fn first_address(&self) -> $addr { <$addr as PrivUnspecAddress>::_Tools::_network_address(