Skip to content

Commit

Permalink
feat: impl TryFrom for HotKey
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jul 18, 2023
1 parent dc9e619 commit b960609
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/try-from.md
@@ -0,0 +1,5 @@
---
"global-hotkey": "patch"
---

Impl `TryFrom<&str>` and `TryFrom<String>` for `HotKey`.
16 changes: 16 additions & 0 deletions src/hotkey.rs
Expand Up @@ -101,6 +101,22 @@ impl FromStr for HotKey {
}
}

impl TryFrom<&str> for HotKey {
type Error = crate::Error;

fn try_from(value: &str) -> Result<Self, Self::Error> {
parse_hotkey(value)
}
}

impl TryFrom<String> for HotKey {
type Error = crate::Error;

fn try_from(value: String) -> Result<Self, Self::Error> {
parse_hotkey(&value)
}
}

fn parse_hotkey(hotkey: &str) -> crate::Result<HotKey> {
let tokens = hotkey.split('+').collect::<Vec<&str>>();

Expand Down

0 comments on commit b960609

Please sign in to comment.