Style and Clippy fixes.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-10-14 16:53:30 +02:00
parent 9efe1b4e22
commit 691bf7c12e
56 changed files with 354 additions and 249 deletions

View File

@@ -10,4 +10,5 @@ mod random;
/// The string_key module defines a custom string handling for reduced allocations and fast lookups
/// and equality checks.
mod string_key;
/// Helper tool to keep track of moving memory for FFI.
mod value_identifier;

View File

@@ -116,11 +116,12 @@ impl Display for StringKey {
}
}
impl Into<StringKey> for &CStr {
fn into(self) -> StringKey {
StringKey::new(self.to_str().unwrap())
impl From<&CStr> for StringKey {
fn from(s: &CStr) -> Self {
StringKey::new(s.to_str().unwrap())
}
}
/// Converts a character to lowercased in a const safe way.
const fn to_lower(c: u8) -> u8 {
if c >= b'A' && c <= b'Z' {
@@ -170,7 +171,7 @@ mod tests {
#[test]
fn create_empty_stringkey() {
let sk = StringKey::new("".into());
let sk = StringKey::new("");
assert_eq!(sk.str(), "");
assert_eq!(sk.hash(), 0);
assert_eq!(sk.hash(), StringKey::get_hash(""));
@@ -178,7 +179,7 @@ mod tests {
#[test]
fn create_stringkey_foo() {
let sk = StringKey::new("foo".into());
let sk = StringKey::new("foo");
assert_eq!(sk.str(), "foo");
assert_eq!(sk.hash(), 2356372769);
assert_eq!(sk.hash(), StringKey::get_hash("foo"));
@@ -187,7 +188,7 @@ mod tests {
#[test]
fn create_stringkey_bar() {
let sk = StringKey::new("bar".into());
let sk = StringKey::new("bar");
assert_eq!(sk.str(), "bar");
assert_eq!(sk.hash(), 1996459178);
assert_eq!(sk.hash(), StringKey::get_hash("bar"));

View File

@@ -1,5 +1,6 @@
use std::sync::atomic::{AtomicUsize, Ordering};
/// The current index for the value counter.
static CURRENT: AtomicUsize = AtomicUsize::new(1);
/// An extremely basic way to identify a piece of data.
@@ -9,9 +10,7 @@ pub struct ValueIdentifier(usize);
impl Default for ValueIdentifier {
fn default() -> Self {
Self {
0: CURRENT.fetch_add(1, Ordering::SeqCst),
}
Self(CURRENT.fetch_add(1, Ordering::SeqCst))
}
}