|
@@ -2,7 +2,7 @@
|
|
|
//!
|
|
|
//! You might want this crate if:
|
|
|
//! - you have a number of string values, the set of which is determined dynamically but does
|
|
|
-//! not grow (much) over time, such as from an initial configuration step, and
|
|
|
+//! not grow (much) over time, such as from an initial configuration step, and
|
|
|
//! - you want to be able to compare these string values repeatedly at very low cost, and
|
|
|
//! - your usage pattern leans towards many comparisons but relatively few parses.
|
|
|
//!
|
|
@@ -46,7 +46,7 @@
|
|
|
//!
|
|
|
//! The use of type aliases is highly encouraged.
|
|
|
|
|
|
-use std::ffi::{OsString, OsStr};
|
|
|
+use std::ffi::{OsStr, OsString};
|
|
|
|
|
|
static STR_STORE: std::sync::LazyLock<std::sync::Mutex<std::collections::HashSet<&'static str>>> =
|
|
|
std::sync::LazyLock::new(Default::default);
|
|
@@ -64,11 +64,11 @@ pub struct StoredString<Tag: 'static> {
|
|
|
|
|
|
impl<Tag: 'static> Clone for StoredString<Tag> {
|
|
|
fn clone(&self) -> Self {
|
|
|
- Self { stored: self.stored, _ghost: Default::default() }
|
|
|
+ *self
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<Tag: 'static> Copy for StoredString<Tag> { }
|
|
|
+impl<Tag: 'static> Copy for StoredString<Tag> {}
|
|
|
|
|
|
impl<Tag: 'static> std::ops::Deref for StoredString<Tag> {
|
|
|
type Target = str;
|
|
@@ -233,10 +233,7 @@ mod test_stored_string {
|
|
|
fn build_test() {
|
|
|
assert_eq!(SS::new("ss"), SS::new("ss"));
|
|
|
|
|
|
- assert_eq!(
|
|
|
- SST::new("ss"),
|
|
|
- SS::new("ss").coerce()
|
|
|
- );
|
|
|
+ assert_eq!(SST::new("ss"), SS::new("ss").coerce());
|
|
|
|
|
|
let ss = SST::new("ss");
|
|
|
let ss2 = ss.clone();
|
|
@@ -247,8 +244,9 @@ mod test_stored_string {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static OS_STR_STORE: std::sync::LazyLock<std::sync::Mutex<std::collections::HashSet<&'static OsStr>>> =
|
|
|
- std::sync::LazyLock::new(Default::default);
|
|
|
+static OS_STR_STORE: std::sync::LazyLock<
|
|
|
+ std::sync::Mutex<std::collections::HashSet<&'static OsStr>>,
|
|
|
+> = std::sync::LazyLock::new(Default::default);
|
|
|
|
|
|
/// See crate documentation for general description.
|
|
|
pub struct StoredOsString<Tag: 'static> {
|
|
@@ -258,11 +256,11 @@ pub struct StoredOsString<Tag: 'static> {
|
|
|
|
|
|
impl<Tag: 'static> Clone for StoredOsString<Tag> {
|
|
|
fn clone(&self) -> Self {
|
|
|
- Self { stored: self.stored, _ghost: Default::default() }
|
|
|
+ *self
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<Tag: 'static> Copy for StoredOsString<Tag> { }
|
|
|
+impl<Tag: 'static> Copy for StoredOsString<Tag> {}
|
|
|
|
|
|
impl<Tag: 'static> std::ops::Deref for StoredOsString<Tag> {
|
|
|
type Target = OsStr;
|
|
@@ -309,7 +307,10 @@ impl<Tag: 'static> PartialOrd for StoredOsString<Tag> {
|
|
|
|
|
|
impl<Tag: 'static> Ord for StoredOsString<Tag> {
|
|
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
|
- self.stored.as_encoded_bytes().as_ptr().cmp(&other.stored.as_encoded_bytes().as_ptr())
|
|
|
+ self.stored
|
|
|
+ .as_encoded_bytes()
|
|
|
+ .as_ptr()
|
|
|
+ .cmp(&other.stored.as_encoded_bytes().as_ptr())
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -357,7 +358,6 @@ impl<'de, Tag: 'static> serde::de::Visitor<'de> for StoredOsStringVisitor<Tag> {
|
|
|
write!(formatter, "stored OsString")
|
|
|
}
|
|
|
|
|
|
-
|
|
|
fn visit_bytes<E: serde::de::Error>(self, v: &[u8]) -> Result<Self::Value, E> {
|
|
|
Ok(StoredOsString::from(v))
|
|
|
}
|