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 170DC1FF2CF for ; Thu, 11 Jul 2024 16:31:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C022635E46; Thu, 11 Jul 2024 16:32:16 +0200 (CEST) Message-ID: <64bb382e-d0f2-45d7-8405-52da740c3ed2@proxmox.com> Date: Thu, 11 Jul 2024 16:32:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Proxmox VE development discussion , Christoph Heiss References: <20240710132756.1149508-1-c.heiss@proxmox.com> <20240710132756.1149508-5-c.heiss@proxmox.com> Content-Language: en-US From: Stefan Hanreich In-Reply-To: <20240710132756.1149508-5-c.heiss@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.641 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 installer 04/14] common: simplify filesystem type serializing & Display trait impl 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" On 7/10/24 15:27, Christoph Heiss wrote: > +impl<'de> Deserialize<'de> for FsType { > + fn deserialize(deserializer: D) -> Result > + where > + D: serde::Deserializer<'de>, > + { > + let fs: String = Deserialize::deserialize(deserializer)?; > + > + match fs.as_str() { > + "ext4" => Ok(FsType::Ext4), > + "xfs" => Ok(FsType::Xfs), > + "zfs (RAID0)" => Ok(FsType::Zfs(ZfsRaidLevel::Raid0)), > + "zfs (RAID1)" => Ok(FsType::Zfs(ZfsRaidLevel::Raid1)), > + "zfs (RAID10)" => Ok(FsType::Zfs(ZfsRaidLevel::Raid10)), > + "zfs (RAIDZ-1)" => Ok(FsType::Zfs(ZfsRaidLevel::RaidZ)), > + "zfs (RAIDZ-2)" => Ok(FsType::Zfs(ZfsRaidLevel::RaidZ2)), > + "zfs (RAIDZ-3)" => Ok(FsType::Zfs(ZfsRaidLevel::RaidZ3)), > + "btrfs (RAID0)" => Ok(FsType::Btrfs(BtrfsRaidLevel::Raid0)), > + "btrfs (RAID1)" => Ok(FsType::Btrfs(BtrfsRaidLevel::Raid1)), > + "btrfs (RAID10)" => Ok(FsType::Btrfs(BtrfsRaidLevel::Raid10)), > + _ => Err(serde::de::Error::custom("could not find file system: {fs}")), > + } > + } > +} Maybe we could implement FromStr here and use serde_plain::derive_deserialize_from_fromstr ? We could even implement FromStr for BtrfsRaidLevel and ZfsRaidLevel and then use that here, but it might be a bit overkill for just this.... > +impl Serialize for FsType { > + fn serialize(&self, serializer: S) -> Result > + where > + S: serde::Serializer, > + { > + let value = match self { > + // proxinstall::$fssetup > + FsType::Ext4 => "ext4", > + FsType::Xfs => "xfs", > + // proxinstall::get_zfs_raid_setup() > + FsType::Zfs(level) => &format!("zfs ({level})"), > + // proxinstall::get_btrfs_raid_setup() > + FsType::Btrfs(level) => &format!("btrfs ({level})"), > + }; > + > + serializer.collect_str(value) > + } > +} Same as above but with Display and serde_plain::derive_display_from_serialize _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel