From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D3E451FF13E for ; Fri, 03 Apr 2026 18:54:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 333D87B2A; Fri, 3 Apr 2026 18:55:25 +0200 (CEST) From: Christoph Heiss To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox v3 07/38] network-types: cidr: implement generic `IpAddr::new` constructor Date: Fri, 3 Apr 2026 18:53:39 +0200 Message-ID: <20260403165437.2166551-8-c.heiss@proxmox.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260403165437.2166551-1-c.heiss@proxmox.com> References: <20260403165437.2166551-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775235262017 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.063 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: NVGVZHYEWZY5J2IFAZRQTWX6UST6ZN2W X-Message-ID-Hash: NVGVZHYEWZY5J2IFAZRQTWX6UST6ZN2W X-MailFrom: c.heiss@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Christoph Heiss --- Changes v2 -> v3: * new patch proxmox-network-types/src/ip_address.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proxmox-network-types/src/ip_address.rs b/proxmox-network-types/src/ip_address.rs index d05877ee..15a73176 100644 --- a/proxmox-network-types/src/ip_address.rs +++ b/proxmox-network-types/src/ip_address.rs @@ -360,6 +360,15 @@ impl Cidr { Ok(Cidr::Ipv6(Ipv6Cidr::new(addr, mask)?)) } + /// Constructs a new [`Cidr`] from an generic [`IpAddr`], which can either be a IPv4 or IPv6 + /// address + pub fn new(addr: impl Into, mask: u8) -> Result { + match addr.into() { + IpAddr::V4(v4) => Self::new_v4(v4, mask), + IpAddr::V6(v6) => Self::new_v6(v6, mask), + } + } + /// Returns the [`Family`] (v4 or v6) this CIDR belongs to. pub const fn family(&self) -> Family { match self { -- 2.53.0