From 22c5009d95f69a01a89a57903539b44342d90659 Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 8 Jul 2026 14:28:01 -0400 Subject: [PATCH] feat: impl `TryFrom` for `NonSpecialMessage` that avoids cloning --- home-assistant/src/notify/service/mobile_app/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/home-assistant/src/notify/service/mobile_app/mod.rs b/home-assistant/src/notify/service/mobile_app/mod.rs index ff442af..d5da68d 100644 --- a/home-assistant/src/notify/service/mobile_app/mod.rs +++ b/home-assistant/src/notify/service/mobile_app/mod.rs @@ -70,6 +70,19 @@ impl FromStr for NonSpecialMessage { } } +impl TryFrom for NonSpecialMessage { + type Error = WasSpecialMessage; + + fn try_from(s: String) -> Result { + match SpecialMessage::from_str(&s) { + Ok(special_message) => Err(WasSpecialMessage { + got: special_message, + }), + Err(_e) => Ok(NonSpecialMessage(s)), + } + } +} + /// How much of a notification is visible on the lock screen #[derive(Debug, Clone, Default, EnumString, strum::Display)] #[strum(serialize_all = "snake_case")]