|
@@ -56,12 +56,19 @@ pub trait NamespaceTag: 'static {
|
|
|
}
|
|
|
|
|
|
/// See crate documentation for general description.
|
|
|
-#[derive(Clone, Copy)]
|
|
|
pub struct StoredString<Tag: 'static> {
|
|
|
stored: &'static str,
|
|
|
_ghost: std::marker::PhantomData<Tag>,
|
|
|
}
|
|
|
|
|
|
+impl<Tag: 'static> Clone for StoredString<Tag> {
|
|
|
+ fn clone(&self) -> Self {
|
|
|
+ Self { stored: self.stored, _ghost: Default::default() }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl<Tag: 'static> Copy for StoredString<Tag> { }
|
|
|
+
|
|
|
impl<Tag: 'static> std::ops::Deref for StoredString<Tag> {
|
|
|
type Target = str;
|
|
|
fn deref(&self) -> &Self::Target {
|
|
@@ -211,13 +218,32 @@ impl<'l, Tag: 'static> From<&'l str> for StoredString<Tag> {
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod test_stored_string {
|
|
|
+ struct TestTag;
|
|
|
+
|
|
|
+ impl super::NamespaceTag for TestTag {
|
|
|
+ const PREFIX: &'static str = "test";
|
|
|
+ }
|
|
|
+
|
|
|
impl super::NamespaceTag for () {
|
|
|
const PREFIX: &'static str = "unit";
|
|
|
}
|
|
|
|
|
|
type SS = super::StoredString<()>;
|
|
|
+ type SST = super::StoredString<TestTag>;
|
|
|
#[test]
|
|
|
fn build_test() {
|
|
|
assert_eq!(SS::new("ss"), SS::new("ss"));
|
|
|
+
|
|
|
+ assert_eq!(
|
|
|
+ SST::new("ss"),
|
|
|
+ SS::new("ss").coerce()
|
|
|
+ );
|
|
|
+
|
|
|
+ let ss = SST::new("ss");
|
|
|
+ let ss2 = ss.clone();
|
|
|
+ let ss3 = ss;
|
|
|
+
|
|
|
+ assert_eq!(ss, ss2);
|
|
|
+ assert_eq!(ss, ss3);
|
|
|
}
|
|
|
}
|