diff --git a/.changes/menu-id-impls.md b/.changes/menu-id-impls.md new file mode 100644 index 0000000..81a792a --- /dev/null +++ b/.changes/menu-id-impls.md @@ -0,0 +1,5 @@ +--- +"muda": "patch" +--- + +Add `PartialEq<&str> for &MenuId` and `PartialEq for &MenuId` implementations. Also add a blanket `From for MenuId` where `T: ToString` implementation. diff --git a/src/menu_id.rs b/src/menu_id.rs index 2eae062..4520256 100644 --- a/src/menu_id.rs +++ b/src/menu_id.rs @@ -17,15 +17,9 @@ impl AsRef for MenuId { } } -impl From for MenuId { - fn from(value: String) -> Self { - Self::new(value) - } -} - -impl From<&str> for MenuId { - fn from(value: &str) -> Self { - Self::new(value) +impl From for MenuId { + fn from(value: T) -> Self { + Self::new(value.to_string()) } } @@ -43,12 +37,24 @@ impl PartialEq<&str> for MenuId { } } +impl PartialEq<&str> for &MenuId { + fn eq(&self, other: &&str) -> bool { + self.0 == *other + } +} + impl PartialEq for MenuId { fn eq(&self, other: &String) -> bool { self.0 == *other } } +impl PartialEq for &MenuId { + fn eq(&self, other: &String) -> bool { + self.0 == *other + } +} + impl PartialEq<&String> for MenuId { fn eq(&self, other: &&String) -> bool { self.0 == **other