Skip to content
Merged
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
19 changes: 18 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,25 @@ mod bumpalloc;
mod hash;
pub use hash::*;
use std::hash::{Hash, Hasher};
use std::cmp::Ordering;

/// A handle representing a string in the global string cache.
///
/// To use, create one using `Ustr::from` or the `ustr` function. You can freely
/// copy, destroy or send Ustrs to other threads: the underlying string is
/// always valid in memory (and is never destroyed).
#[derive(Copy, Clone, PartialEq, PartialOrd)]
#[derive(Copy, Clone, PartialEq)]
#[repr(transparent)]
pub struct Ustr {
char_ptr: *const u8,
}

impl PartialOrd for Ustr {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.as_str().partial_cmp(other.as_str())
}
}

impl Ustr {
/// Create a new Ustr from the given &str.
///
Expand Down Expand Up @@ -697,6 +704,16 @@ mod tests {

assert_eq!(u_hello, me_hello);
}

#[test]
fn partial_ord() {
use super::ustr;
let str_a = ustr("aaa");
let str_z = ustr("zzz");
let str_k = ustr("kkk");
assert!(str_a < str_k);
assert!(str_k < str_z);
}
}

lazy_static::lazy_static! {
Expand Down