mirror of
https://github.com/italicsjenga/muda.git
synced 2025-01-10 03:41:30 +11:00
refactor: dereference in partial_eq and add tests
This commit is contained in:
parent
121c97519f
commit
829051a30a
5
.changes/derefence.md
Normal file
5
.changes/derefence.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"muda": "patch"
|
||||||
|
---
|
||||||
|
|
||||||
|
Dereference `&String` and `&&str` in `PartialEq` for `MenuId` type
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{convert::Infallible, str::FromStr};
|
use std::{convert::Infallible, str::FromStr};
|
||||||
|
|
||||||
/// An unique id that is associated with a menu item.
|
/// An unique id that is associated with a menu or a menu item.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
|
||||||
pub struct MenuId(pub String);
|
pub struct MenuId(pub String);
|
||||||
|
|
||||||
|
@ -39,19 +39,19 @@ impl FromStr for MenuId {
|
||||||
|
|
||||||
impl PartialEq<&str> for MenuId {
|
impl PartialEq<&str> for MenuId {
|
||||||
fn eq(&self, other: &&str) -> bool {
|
fn eq(&self, other: &&str) -> bool {
|
||||||
other == &self.0
|
self.0 == *other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<String> for MenuId {
|
impl PartialEq<String> for MenuId {
|
||||||
fn eq(&self, other: &String) -> bool {
|
fn eq(&self, other: &String) -> bool {
|
||||||
other == &self.0
|
self.0 == *other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<&String> for MenuId {
|
impl PartialEq<&String> for MenuId {
|
||||||
fn eq(&self, other: &&String) -> bool {
|
fn eq(&self, other: &&String) -> bool {
|
||||||
other == &&self.0
|
self.0 == **other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,3 +60,19 @@ impl PartialEq<&MenuId> for MenuId {
|
||||||
other.0 == self.0
|
other.0 == self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::MenuId;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_eq() {
|
||||||
|
assert_eq!(MenuId::new("t"), "t",);
|
||||||
|
assert_eq!(MenuId::new("t"), String::from("t"));
|
||||||
|
assert_eq!(MenuId::new("t"), &String::from("t"));
|
||||||
|
assert_eq!(MenuId::new("t"), MenuId::new("t"));
|
||||||
|
assert_eq!(MenuId::new("t"), &MenuId::new("t"));
|
||||||
|
assert_eq!(&MenuId::new("t"), &MenuId::new("t"));
|
||||||
|
assert_eq!(MenuId::new("t").as_ref(), "t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue