This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::{ValueIdentifiable, ValueIdentifier};
|
||||
use arcstr::ArcStr;
|
||||
use hashbrown::HashMap;
|
||||
use parking_lot::RwLock;
|
||||
@@ -13,7 +14,7 @@ use std::sync::LazyLock;
|
||||
/// free speed out of it. Note that StringKeys also compare case insensitive, so that for example
|
||||
/// `charmander` == `Charmander`.
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
|
||||
pub struct StringKey {
|
||||
/// The underlying reference counted string.
|
||||
str: ArcStr,
|
||||
@@ -122,6 +123,12 @@ impl From<&CStr> for StringKey {
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueIdentifiable for StringKey {
|
||||
fn value_identifier(&self) -> ValueIdentifier {
|
||||
ValueIdentifier::new(self.hash as usize)
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a character to lowercased in a const safe way.
|
||||
const fn to_lower(c: u8) -> u8 {
|
||||
if c >= b'A' && c <= b'Z' {
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
static CURRENT: AtomicUsize = AtomicUsize::new(1);
|
||||
|
||||
/// An extremely basic way to identify a piece of data.
|
||||
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||
#[repr(C)]
|
||||
pub struct ValueIdentifier(usize);
|
||||
|
||||
@@ -14,6 +14,18 @@ impl Default for ValueIdentifier {
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueIdentifier {
|
||||
/// Creates an identifier by number.
|
||||
pub(crate) fn new(v: usize) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
|
||||
/// Get the underlying numeric integer of the value
|
||||
pub fn value(&self) -> usize {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// An object with a specific identifier.
|
||||
pub trait ValueIdentifiable {
|
||||
/// Get the identifier for the current object.
|
||||
|
||||
Reference in New Issue
Block a user