From b96060952daf8959939f07c968b8bd58e33f4abd Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 18 Jul 2023 04:30:39 +0300 Subject: [PATCH] feat: impl `TryFrom` for `HotKey` --- .changes/try-from.md | 5 +++++ src/hotkey.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .changes/try-from.md diff --git a/.changes/try-from.md b/.changes/try-from.md new file mode 100644 index 0000000..3183568 --- /dev/null +++ b/.changes/try-from.md @@ -0,0 +1,5 @@ +--- +"global-hotkey": "patch" +--- + +Impl `TryFrom<&str>` and `TryFrom` for `HotKey`. diff --git a/src/hotkey.rs b/src/hotkey.rs index 6614535..dec8432 100644 --- a/src/hotkey.rs +++ b/src/hotkey.rs @@ -101,6 +101,22 @@ impl FromStr for HotKey { } } +impl TryFrom<&str> for HotKey { + type Error = crate::Error; + + fn try_from(value: &str) -> Result { + parse_hotkey(value) + } +} + +impl TryFrom for HotKey { + type Error = crate::Error; + + fn try_from(value: String) -> Result { + parse_hotkey(&value) + } +} + fn parse_hotkey(hotkey: &str) -> crate::Result { let tokens = hotkey.split('+').collect::>();