From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 950B01FF17C for <inbox@lore.proxmox.com>; Wed, 30 Apr 2025 09:30:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B51441BA31; Wed, 30 Apr 2025 09:30:19 +0200 (CEST) From: Dominik Csapak <d.csapak@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Wed, 30 Apr 2025 09:29:35 +0200 Message-Id: <20250430072936.447054-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250430072936.447054-1-d.csapak@proxmox.com> References: <20250430072936.447054-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.021 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [status.rs] Subject: [pdm-devel] [PATCH yew-comp 1/1] status: replace `to_fa_icon` with From implementation X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> this is a much nicer interface, and more idiomatic rust. To not break all sites that use it, simply deprecate the old `to_fa_icon` for now Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> --- src/status.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/status.rs b/src/status.rs index a2866d1..1004012 100644 --- a/src/status.rs +++ b/src/status.rs @@ -16,13 +16,25 @@ pub enum Status { } impl Status { + #[deprecated] + /// Deprecated, please use [`Fa::from`] or `.into()` instead. pub fn to_fa_icon(&self) -> Fa { - let (icon, class): (&str, Classes) = match self { + (*self).into() + } + + fn get_icon_classes(&self) -> (&str, Classes) { + match self { Status::Success => ("check", FontColor::Success.into()), Status::Warning => ("exclamation-triangle", FontColor::Warning.into()), Status::Error => ("times-circle", FontColor::Error.into()), Status::Unknown => ("question-circle", Opacity::Quarter.into()), - }; + } + } +} + +impl From<Status> for Fa { + fn from(value: Status) -> Self { + let (icon, class) = value.get_icon_classes(); Fa::new(icon).class(class) } } @@ -36,12 +48,24 @@ pub enum NodeState { } impl NodeState { + #[deprecated] + /// Deprecated, please use [`Fa::from`] or `.into()` instead. pub fn to_fa_icon(&self) -> Fa { - let (icon, class) = match self { + (*self).into() + } + + fn get_icon_classes(&self) -> (&str, FontColor) { + match self { NodeState::Online => ("check-circle", FontColor::Success), NodeState::Offline => ("times-circle", FontColor::Error), NodeState::Unknown => ("question-circle", FontColor::Surface), - }; + } + } +} + +impl From<NodeState> for Fa { + fn from(value: NodeState) -> Self { + let (icon, class) = value.get_icon_classes(); Fa::new(icon).class(class) } } @@ -57,14 +81,26 @@ pub enum GuestState { } impl GuestState { + #[deprecated] + /// Deprecated, please use [`Fa::from`] or `.into()` instead. pub fn to_fa_icon(&self) -> Fa { - let (icon, class): (&str, Classes) = match self { + (*self).into() + } + + fn get_icon_classes(&self) -> (&str, Classes) { + match self { GuestState::Running => ("play", FontColor::Success.into()), GuestState::Paused => ("pause", FontColor::Warning.into()), GuestState::Stopped => ("stop", Opacity::Quarter.into()), GuestState::Template => ("file-o", "".into()), GuestState::Unknown => ("question-circle", Opacity::Quarter.into()), - }; + } + } +} + +impl From<GuestState> for Fa { + fn from(value: GuestState) -> Self { + let (icon, class) = value.get_icon_classes(); Fa::new(icon).class(class) } } @@ -78,12 +114,24 @@ pub enum StorageState { } impl StorageState { + #[deprecated] + /// Deprecated, please use [`Fa::from`] or `.into()` instead. pub fn to_fa_icon(&self) -> Fa { - let (icon, class) = match self { + (*self).into() + } + + fn get_icon_classes(&self) -> (&str, FontColor) { + match self { StorageState::Available => ("check-circle", FontColor::Success), StorageState::Unavailable => ("times-circle", FontColor::Error), StorageState::Unknown => ("question-circle", FontColor::Warning), - }; + } + } +} + +impl From<StorageState> for Fa { + fn from(value: StorageState) -> Self { + let (icon, class) = value.get_icon_classes(); Fa::new(icon).class(class) } } -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel