From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1B1BFBCD1D for ; Fri, 29 Mar 2024 13:39:11 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F01C91B18D for ; Fri, 29 Mar 2024 13:38:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 29 Mar 2024 13:38:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1F55E42B17 for ; Fri, 29 Mar 2024 13:38:40 +0100 (CET) Message-ID: <9fdb3402-f014-4979-ac39-f5fb9febfd29@proxmox.com> Date: Fri, 29 Mar 2024 13:38:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Christoph Heiss Cc: Proxmox VE development discussion References: <20240328135028.504520-1-a.lauterer@proxmox.com> <20240328135028.504520-28-a.lauterer@proxmox.com> From: Aaron Lauterer In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.058 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 Subject: Re: [pve-devel] [PATCH v3 27/30] common: add deserializer for FsType X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Mar 2024 12:39:11 -0000 On 2024-03-29 13:20, Christoph Heiss wrote: > On Thu, Mar 28, 2024 at 02:50:25PM +0100, Aaron Lauterer wrote: >> Signed-off-by: Aaron Lauterer >> --- > [..] >> diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs >> index 8432a2c..743e7a9 100644 >> --- a/proxmox-installer-common/src/setup.rs >> +++ b/proxmox-installer-common/src/setup.rs > [..] >> @@ -471,3 +472,39 @@ where >> >> serializer.collect_str(value) >> } >> + >> +pub fn deserialize_fs_type<'de, D>(deserializer: D) -> Result >> +where >> + D: Deserializer<'de>, >> +{ >> + let de_fs: String = Deserialize::deserialize(deserializer)?; >> + >> + let fs; >> + let mut raid: Option = None; >> + let re_raid = Regex::new(r"^(?P.*) \((?P.*)\)$").map_err(de::Error::custom)?; >> + match re_raid.captures(de_fs.as_str()) { >> + Some(caps) => { >> + fs = caps.name("fs").unwrap().as_str().to_lowercase(); >> + raid = Some(caps.name("raid").unwrap().as_str().to_lowercase()); >> + }, >> + None => fs = de_fs, >> + } > > (nit I guess?) Instead of using a regex here (which also bloats the > binary considerably), I'd IMO prefer a dumb `match` like in > serialize_fstype() above. > > Would be much easier to read & reason about, at least. (and probably > less code in total as well) Yeah, sounds reasonable. :) > >> + >> + match fs { >> + t if t == "zfs" => { >> + let raidlevel: ZfsRaidLevel = Deserialize::deserialize(serde_json::Value::String(raid.unwrap())) >> + .map_err(de::Error::custom)?; >> + Ok(FsType::Zfs(raidlevel)) >> + } >> + t if t == "btrfs" => { >> + let raidlevel: BtrfsRaidLevel = Deserialize::deserialize(serde_json::Value::String(raid.unwrap())) >> + .map_err(de::Error::custom)?; >> + Ok(FsType::Btrfs(raidlevel)) >> + } >> + t => { >> + let fstype: FsType = Deserialize::deserialize(serde_json::Value::String(t)) >> + .map_err(de::Error::custom)?; >> + Ok(fstype) >> + } >> + } >> +} >> -- >> 2.39.2 >> >> >> >> _______________________________________________ >> pve-devel mailing list >> pve-devel@lists.proxmox.com >> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >> >>