Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/kv/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,25 @@ mod tests {
fn key_to_borrowed() {
assert_eq!("a key", Key::from_str("a key").to_borrowed_str().unwrap());
}

#[test]
fn key_static_eq() {
assert_eq!(Key::from_str_static("a key"), Key::from_str_static("a key"));
}

#[test]
fn key_borrowed_eq() {
const KEY: &str = "a key";
let k1 = String::from(KEY);
let k2 = String::from(KEY);
assert_eq!(Key::from_str(&k1), Key::from_str(&k2));
}

#[test]
fn key_borrowed_and_static_eq() {
const KEY: &str = "a key";
let static_key = Key::from_str_static(KEY);
let borrowed_key = Key::from_str(KEY);
assert_eq!(static_key, borrowed_key);
}
}
28 changes: 27 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ impl LevelFilter {
}
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[derive(Copy, Clone, Debug)]
enum MaybeStaticStr<'a> {
Static(&'static str),
Borrowed(&'a str),
Expand All @@ -793,6 +793,32 @@ impl<'a> MaybeStaticStr<'a> {
}
}

impl Eq for MaybeStaticStr<'_> {}

impl PartialEq for MaybeStaticStr<'_> {
fn eq(&self, other: &Self) -> bool {
self.get() == other.get()
}
}

impl Ord for MaybeStaticStr<'_> {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.get().cmp(other.get())
}
}

impl PartialOrd for MaybeStaticStr<'_> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl std::hash::Hash for MaybeStaticStr<'_> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.get().hash(state);
}
}

/// The "payload" of a log message.
///
/// # Use
Expand Down