Loads of cleanup
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
2022-11-27 17:29:29 +01:00
parent aa3ceaed3e
commit efd1acdfa5
45 changed files with 259 additions and 162 deletions

View File

@@ -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' {

View File

@@ -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.