|
|
|
@ -1,10 +1,7 @@
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
// See Notices.txt for copyright information
|
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
use crate::{
|
|
|
|
|
intern::type_map::TypeIdMap,
|
|
|
|
|
util::{ConstBool, GenericConstBool},
|
|
|
|
|
};
|
|
|
|
|
use crate::intern::type_map::TypeIdMap;
|
|
|
|
|
use bitvec::{ptr::BitPtr, slice::BitSlice, vec::BitVec};
|
|
|
|
|
use hashbrown::{hash_map::RawEntryMut, HashMap, HashTable};
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
@ -297,221 +294,94 @@ impl InternedCompare for str {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait InternContext: 'static + Send + Sync + Hash + Ord + fmt::Debug + Clone {
|
|
|
|
|
type InternedImpl<T: ?Sized + 'static + Send + Sync>: 'static + Send + Sync + Clone;
|
|
|
|
|
type InternedGuardImpl<T: ?Sized + 'static + Send + Sync>: 'static
|
|
|
|
|
+ Send
|
|
|
|
|
+ Sync
|
|
|
|
|
+ Clone
|
|
|
|
|
+ Borrow<T>;
|
|
|
|
|
type AllContextsAreIdentical: GenericConstBool;
|
|
|
|
|
fn interned_compare_key<T: InternedCompare + ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: &Self::InternedImpl<T>,
|
|
|
|
|
) -> T::InternedCompareKey {
|
|
|
|
|
T::interned_compare_key_ref(Self::guard(v).borrow())
|
|
|
|
|
pub trait Intern: Any + Send + Sync {
|
|
|
|
|
fn intern(&self) -> Interned<Self>;
|
|
|
|
|
fn intern_sized(self) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: Clone,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_owned(self)
|
|
|
|
|
}
|
|
|
|
|
fn guard<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: &Self::InternedImpl<T>,
|
|
|
|
|
) -> Self::InternedGuardImpl<T>;
|
|
|
|
|
fn try_guard<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: &Self::InternedImpl<T>,
|
|
|
|
|
) -> Option<Self::InternedGuardImpl<T>>;
|
|
|
|
|
fn into_guard<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: Self::InternedImpl<T>,
|
|
|
|
|
) -> Self::InternedGuardImpl<T> {
|
|
|
|
|
Self::guard(&v)
|
|
|
|
|
fn intern_owned(this: <Self as ToOwned>::Owned) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_cow(Cow::Owned(this))
|
|
|
|
|
}
|
|
|
|
|
fn unguard<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: &Self::InternedGuardImpl<T>,
|
|
|
|
|
) -> Self::InternedImpl<T>;
|
|
|
|
|
fn unguard_move<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: Self::InternedGuardImpl<T>,
|
|
|
|
|
) -> Self::InternedImpl<T> {
|
|
|
|
|
Self::unguard(&v)
|
|
|
|
|
fn intern_cow(this: Cow<'_, Self>) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
this.intern()
|
|
|
|
|
}
|
|
|
|
|
fn alloc_str(&self, value: Cow<'_, str>) -> Self::InternedGuardImpl<str>;
|
|
|
|
|
fn alloc_slice<T: Clone + Send + Sync + 'static>(
|
|
|
|
|
&self,
|
|
|
|
|
value: Cow<'_, [T]>,
|
|
|
|
|
) -> Self::InternedGuardImpl<[T]>;
|
|
|
|
|
fn alloc_sized<T: Clone + Send + Sync + 'static>(
|
|
|
|
|
&self,
|
|
|
|
|
value: Cow<'_, T>,
|
|
|
|
|
) -> Self::InternedGuardImpl<T>;
|
|
|
|
|
fn interner<T: ?Sized + Send + Sync + 'static>(&self) -> &Interner<T, Self>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait BitSliceInternContext: InternContext {
|
|
|
|
|
fn alloc_bit_slice(&self, value: Cow<'_, BitSlice>) -> Self::InternedGuardImpl<BitSlice>;
|
|
|
|
|
pub struct Interner<T: ?Sized + 'static + Send + Sync> {
|
|
|
|
|
map: Mutex<HashMap<&'static T, ()>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
|
|
|
|
|
pub struct GlobalContext;
|
|
|
|
|
|
|
|
|
|
impl InternContext for GlobalContext {
|
|
|
|
|
type InternedImpl<T: ?Sized + 'static + Send + Sync> = &'static T;
|
|
|
|
|
type InternedGuardImpl<T: ?Sized + 'static + Send + Sync> = &'static T;
|
|
|
|
|
type AllContextsAreIdentical = ConstBool<true>;
|
|
|
|
|
|
|
|
|
|
fn guard<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: &Self::InternedImpl<T>,
|
|
|
|
|
) -> Self::InternedGuardImpl<T> {
|
|
|
|
|
*v
|
|
|
|
|
}
|
|
|
|
|
fn try_guard<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: &Self::InternedImpl<T>,
|
|
|
|
|
) -> Option<Self::InternedGuardImpl<T>> {
|
|
|
|
|
Some(*v)
|
|
|
|
|
}
|
|
|
|
|
fn unguard<T: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
v: &Self::InternedGuardImpl<T>,
|
|
|
|
|
) -> Self::InternedImpl<T> {
|
|
|
|
|
*v
|
|
|
|
|
}
|
|
|
|
|
fn alloc_str(&self, value: Cow<'_, str>) -> Self::InternedGuardImpl<str> {
|
|
|
|
|
value.into_owned().leak()
|
|
|
|
|
}
|
|
|
|
|
fn alloc_slice<T: Clone + Send + Sync + 'static>(
|
|
|
|
|
&self,
|
|
|
|
|
value: Cow<'_, [T]>,
|
|
|
|
|
) -> Self::InternedGuardImpl<[T]> {
|
|
|
|
|
value.into_owned().leak()
|
|
|
|
|
}
|
|
|
|
|
fn alloc_sized<T: Clone + Send + Sync + 'static>(
|
|
|
|
|
&self,
|
|
|
|
|
value: Cow<'_, T>,
|
|
|
|
|
) -> Self::InternedGuardImpl<T> {
|
|
|
|
|
Box::leak(Box::new(value.into_owned()))
|
|
|
|
|
}
|
|
|
|
|
fn interner<T: ?Sized + 'static + Send + Sync>(&self) -> &Interner<T, Self> {
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync> Interner<T> {
|
|
|
|
|
fn get() -> &'static Interner<T> {
|
|
|
|
|
static TYPE_ID_MAP: TypeIdMap = TypeIdMap::new();
|
|
|
|
|
TYPE_ID_MAP.get_or_insert_default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl BitSliceInternContext for GlobalContext {
|
|
|
|
|
fn alloc_bit_slice(&self, value: Cow<'_, BitSlice>) -> Self::InternedGuardImpl<BitSlice> {
|
|
|
|
|
value.into_owned().leak()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait Intern<C: InternContext = GlobalContext>: Any + Send + Sync {
|
|
|
|
|
fn intern_with_ctx(&self, context: &C) -> Interned<Self, C>;
|
|
|
|
|
fn intern_sized_with_ctx(self, context: &C) -> Interned<Self, C>
|
|
|
|
|
where
|
|
|
|
|
Self: Clone,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_owned_with_ctx(self, context)
|
|
|
|
|
}
|
|
|
|
|
fn intern_owned_with_ctx(this: <Self as ToOwned>::Owned, context: &C) -> Interned<Self, C>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Owned(this), context)
|
|
|
|
|
}
|
|
|
|
|
fn intern_cow_with_ctx(this: Cow<'_, Self>, context: &C) -> Interned<Self, C>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
this.intern_with_ctx(context)
|
|
|
|
|
}
|
|
|
|
|
fn intern(&self) -> Interned<Self, C>
|
|
|
|
|
where
|
|
|
|
|
C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default,
|
|
|
|
|
{
|
|
|
|
|
self.intern_with_ctx(&C::default())
|
|
|
|
|
}
|
|
|
|
|
fn intern_sized(self) -> Interned<Self, C>
|
|
|
|
|
where
|
|
|
|
|
Self: Clone,
|
|
|
|
|
C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default,
|
|
|
|
|
{
|
|
|
|
|
self.intern_sized_with_ctx(&C::default())
|
|
|
|
|
}
|
|
|
|
|
fn intern_owned(this: <Self as ToOwned>::Owned) -> Interned<Self, C>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_owned_with_ctx(this, &C::default())
|
|
|
|
|
}
|
|
|
|
|
fn intern_cow(this: Cow<'_, Self>) -> Interned<Self, C>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_cow_with_ctx(this, &C::default())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Interner<T: ?Sized + 'static + Send + Sync, C: InternContext> {
|
|
|
|
|
map: Mutex<HashMap<C::InternedGuardImpl<T>, ()>>,
|
|
|
|
|
_phantom: PhantomData<fn(&C)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Default for Interner<T, C> {
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync> Default for Interner<T> {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
map: Default::default(),
|
|
|
|
|
_phantom: Default::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + Hash + Eq + ToOwned, C: InternContext> Interner<T, C> {
|
|
|
|
|
fn intern<F: FnOnce(Cow<'_, T>) -> C::InternedGuardImpl<T>>(
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + Hash + Eq + ToOwned> Interner<T> {
|
|
|
|
|
fn intern<F: FnOnce(Cow<'_, T>) -> &'static T>(
|
|
|
|
|
&self,
|
|
|
|
|
alloc: F,
|
|
|
|
|
value: Cow<'_, T>,
|
|
|
|
|
) -> Interned<T, C> {
|
|
|
|
|
) -> Interned<T> {
|
|
|
|
|
let mut map = self.map.lock().unwrap();
|
|
|
|
|
let hasher = map.hasher().clone();
|
|
|
|
|
let hash = hasher.hash_one(&*value);
|
|
|
|
|
let inner = match map
|
|
|
|
|
.raw_entry_mut()
|
|
|
|
|
.from_hash(hash, |k| k.borrow() == &*value)
|
|
|
|
|
{
|
|
|
|
|
RawEntryMut::Occupied(entry) => C::unguard(entry.key()),
|
|
|
|
|
RawEntryMut::Vacant(entry) => C::unguard(
|
|
|
|
|
entry
|
|
|
|
|
.insert_with_hasher(hash, alloc(value), (), |k| hasher.hash_one(k.borrow()))
|
|
|
|
|
.0,
|
|
|
|
|
),
|
|
|
|
|
let inner = match map.raw_entry_mut().from_hash(hash, |k| **k == *value) {
|
|
|
|
|
RawEntryMut::Occupied(entry) => *entry.key(),
|
|
|
|
|
RawEntryMut::Vacant(entry) => {
|
|
|
|
|
*entry
|
|
|
|
|
.insert_with_hasher(hash, alloc(value), (), |k| hasher.hash_one(&**k))
|
|
|
|
|
.0
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Interned {
|
|
|
|
|
inner,
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
Interned { inner }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync + Hash + Eq, C: InternContext> Interner<T, C> {
|
|
|
|
|
fn intern_sized(&self, context: &C, value: Cow<'_, T>) -> Interned<T, C> {
|
|
|
|
|
self.intern(|value| context.alloc_sized(value), value)
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync + Hash + Eq> Interner<T> {
|
|
|
|
|
fn intern_sized(&self, value: Cow<'_, T>) -> Interned<T> {
|
|
|
|
|
self.intern(|value| Box::leak(Box::new(value.into_owned())), value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync + Hash + Eq, C: InternContext> Interner<[T], C> {
|
|
|
|
|
fn intern_slice(&self, context: &C, value: Cow<'_, [T]>) -> Interned<[T], C> {
|
|
|
|
|
self.intern(|value| context.alloc_slice(value), value)
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync + Hash + Eq> Interner<[T]> {
|
|
|
|
|
fn intern_slice(&self, value: Cow<'_, [T]>) -> Interned<[T]> {
|
|
|
|
|
self.intern(|value| value.into_owned().leak(), value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<C: BitSliceInternContext> Interner<BitSlice, C> {
|
|
|
|
|
fn intern_bit_slice(&self, context: &C, value: Cow<'_, BitSlice>) -> Interned<BitSlice, C> {
|
|
|
|
|
self.intern(|value| context.alloc_bit_slice(value), value)
|
|
|
|
|
impl Interner<BitSlice> {
|
|
|
|
|
fn intern_bit_slice(&self, value: Cow<'_, BitSlice>) -> Interned<BitSlice> {
|
|
|
|
|
self.intern(|value| value.into_owned().leak(), value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<C: InternContext> Interner<str, C> {
|
|
|
|
|
fn intern_str(&self, context: &C, value: Cow<'_, str>) -> Interned<str, C> {
|
|
|
|
|
self.intern(|value| context.alloc_str(value), value)
|
|
|
|
|
impl Interner<str> {
|
|
|
|
|
fn intern_str(&self, value: Cow<'_, str>) -> Interned<str> {
|
|
|
|
|
self.intern(|value| value.into_owned().leak(), value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Interned<T: ?Sized + 'static + Send + Sync, C: InternContext = GlobalContext> {
|
|
|
|
|
inner: C::InternedImpl<T>,
|
|
|
|
|
_phantom: PhantomData<&'static C>,
|
|
|
|
|
pub struct Interned<T: ?Sized + 'static + Send + Sync> {
|
|
|
|
|
inner: &'static T,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
macro_rules! forward_fmt_trait {
|
|
|
|
@ -522,23 +392,9 @@ macro_rules! forward_fmt_trait {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + fmt::$Tr, C: InternContext> fmt::$Tr
|
|
|
|
|
for Interned<T, C>
|
|
|
|
|
{
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + fmt::$Tr> fmt::$Tr for Interned<T> {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
if let Some(guard) = C::try_guard(&self.inner) {
|
|
|
|
|
guard.borrow().fmt(f)
|
|
|
|
|
} else {
|
|
|
|
|
write!(f, "<Expired>")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + fmt::$Tr, C: InternContext> fmt::$Tr
|
|
|
|
|
for Guard<T, C>
|
|
|
|
|
{
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
self.inner.borrow().fmt(f)
|
|
|
|
|
self.inner.fmt(f)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -554,18 +410,16 @@ forward_fmt_trait!(UpperExp);
|
|
|
|
|
forward_fmt_trait!(UpperHex);
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub struct InternedSliceIter<T: Clone + 'static + Send + Sync, C: InternContext> {
|
|
|
|
|
slice: Interned<[T], C>,
|
|
|
|
|
pub struct InternedSliceIter<T: Clone + 'static + Send + Sync> {
|
|
|
|
|
slice: Interned<[T]>,
|
|
|
|
|
index: std::ops::Range<usize>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync, C: InternContext> Iterator for InternedSliceIter<T, C> {
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync> Iterator for InternedSliceIter<T> {
|
|
|
|
|
type Item = T;
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
|
self.index
|
|
|
|
|
.next()
|
|
|
|
|
.map(|index| self.slice.guard()[index].clone())
|
|
|
|
|
self.index.next().map(|index| self.slice[index].clone())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
@ -573,233 +427,186 @@ impl<T: Clone + 'static + Send + Sync, C: InternContext> Iterator for InternedSl
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync, C: InternContext> DoubleEndedIterator
|
|
|
|
|
for InternedSliceIter<T, C>
|
|
|
|
|
{
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync> DoubleEndedIterator for InternedSliceIter<T> {
|
|
|
|
|
fn next_back(&mut self) -> Option<Self::Item> {
|
|
|
|
|
self.index
|
|
|
|
|
.next_back()
|
|
|
|
|
.map(|index| self.slice.guard()[index].clone())
|
|
|
|
|
.map(|index| self.slice[index].clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync, C: InternContext> FusedIterator for InternedSliceIter<T, C> {}
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync> FusedIterator for InternedSliceIter<T> {}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync, C: InternContext> ExactSizeIterator
|
|
|
|
|
for InternedSliceIter<T, C>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync> ExactSizeIterator for InternedSliceIter<T> {}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync, C: InternContext> IntoIterator for Interned<[T], C> {
|
|
|
|
|
impl<T: Clone + 'static + Send + Sync> IntoIterator for Interned<[T]> {
|
|
|
|
|
type Item = T;
|
|
|
|
|
type IntoIter = InternedSliceIter<T, C>;
|
|
|
|
|
type IntoIter = InternedSliceIter<T>;
|
|
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
|
InternedSliceIter {
|
|
|
|
|
index: 0..self.guard().len(),
|
|
|
|
|
index: 0..self.len(),
|
|
|
|
|
slice: self,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, T: 'static + Send + Sync, C: InternContext> IntoIterator for &'a Interned<[T], C>
|
|
|
|
|
where
|
|
|
|
|
C::InternedImpl<[T]>: Borrow<[T]>,
|
|
|
|
|
{
|
|
|
|
|
impl<'a, T: 'static + Send + Sync> IntoIterator for &'a Interned<[T]> {
|
|
|
|
|
type Item = &'a T;
|
|
|
|
|
type IntoIter = std::slice::Iter<'a, T>;
|
|
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
|
self.inner.borrow().iter()
|
|
|
|
|
self.inner.iter()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, T: 'static + Send + Sync, C: InternContext> IntoIterator for &'a mut Interned<[T], C>
|
|
|
|
|
where
|
|
|
|
|
C::InternedImpl<[T]>: Borrow<[T]>,
|
|
|
|
|
{
|
|
|
|
|
impl<'a, T: 'static + Send + Sync> IntoIterator for &'a mut Interned<[T]> {
|
|
|
|
|
type Item = &'a T;
|
|
|
|
|
type IntoIter = std::slice::Iter<'a, T>;
|
|
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
|
self.inner.borrow().iter()
|
|
|
|
|
self.inner.iter()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<I: Clone, C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default>
|
|
|
|
|
FromIterator<I> for Interned<[I], C>
|
|
|
|
|
impl<I: Clone> FromIterator<I> for Interned<[I]>
|
|
|
|
|
where
|
|
|
|
|
[I]: Intern<C>,
|
|
|
|
|
[I]: Intern,
|
|
|
|
|
{
|
|
|
|
|
fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self {
|
|
|
|
|
Intern::intern_owned(Vec::from_iter(iter))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: 'static + Clone + Send + Sync, C: InternContext> From<Interned<[T], C>> for Vec<T> {
|
|
|
|
|
fn from(value: Interned<[T], C>) -> Self {
|
|
|
|
|
Vec::from(&*value.guard())
|
|
|
|
|
impl<T: 'static + Clone + Send + Sync> From<Interned<[T]>> for Vec<T> {
|
|
|
|
|
fn from(value: Interned<[T]>) -> Self {
|
|
|
|
|
Vec::from(&*value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: 'static + Clone + Send + Sync, C: InternContext> From<Interned<[T], C>> for Box<[T]> {
|
|
|
|
|
fn from(value: Interned<[T], C>) -> Self {
|
|
|
|
|
Box::from(&*value.guard())
|
|
|
|
|
impl<T: 'static + Clone + Send + Sync> From<Interned<[T]>> for Box<[T]> {
|
|
|
|
|
fn from(value: Interned<[T]>) -> Self {
|
|
|
|
|
Box::from(&*value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<C: InternContext> From<Interned<str, C>> for String {
|
|
|
|
|
fn from(value: Interned<str, C>) -> Self {
|
|
|
|
|
String::from(&*value.guard())
|
|
|
|
|
impl From<Interned<str>> for String {
|
|
|
|
|
fn from(value: Interned<str>) -> Self {
|
|
|
|
|
String::from(&*value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<I, C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default> Default
|
|
|
|
|
for Interned<[I], C>
|
|
|
|
|
impl<I> Default for Interned<[I]>
|
|
|
|
|
where
|
|
|
|
|
[I]: Intern<C>,
|
|
|
|
|
[I]: Intern,
|
|
|
|
|
{
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
[][..].intern()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default> Default
|
|
|
|
|
for Interned<str, C>
|
|
|
|
|
where
|
|
|
|
|
str: Intern<C>,
|
|
|
|
|
{
|
|
|
|
|
impl Default for Interned<str> {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
"".intern()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<C: BitSliceInternContext<AllContextsAreIdentical = ConstBool<true>> + Default> Default
|
|
|
|
|
for Interned<BitSlice, C>
|
|
|
|
|
where
|
|
|
|
|
BitSlice: Intern<C>,
|
|
|
|
|
{
|
|
|
|
|
impl Default for Interned<BitSlice> {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
<&BitSlice>::default().intern()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<I: Clone + Default, C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default>
|
|
|
|
|
Default for Interned<I, C>
|
|
|
|
|
impl<I: Clone + Default> Default for Interned<I>
|
|
|
|
|
where
|
|
|
|
|
I: Intern<C>,
|
|
|
|
|
I: Intern,
|
|
|
|
|
{
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
I::default().intern()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Interned<T, C> {
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync> Interned<T> {
|
|
|
|
|
pub fn cast_unchecked<U: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
this: Self,
|
|
|
|
|
f: impl FnOnce(C::InternedImpl<T>) -> C::InternedImpl<U>,
|
|
|
|
|
) -> Interned<U, C> {
|
|
|
|
|
f: impl FnOnce(&'static T) -> &'static U,
|
|
|
|
|
) -> Interned<U> {
|
|
|
|
|
Interned {
|
|
|
|
|
inner: f(this.inner),
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn try_cast_unchecked<U: ?Sized + 'static + Send + Sync, E>(
|
|
|
|
|
this: Self,
|
|
|
|
|
f: impl FnOnce(C::InternedImpl<T>) -> Result<C::InternedImpl<U>, E>,
|
|
|
|
|
) -> Result<Interned<U, C>, E> {
|
|
|
|
|
f: impl FnOnce(&'static T) -> Result<&'static U, E>,
|
|
|
|
|
) -> Result<Interned<U>, E> {
|
|
|
|
|
Ok(Interned {
|
|
|
|
|
inner: f(this.inner)?,
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
pub fn into_inner(this: Self) -> C::InternedImpl<T> {
|
|
|
|
|
pub fn into_inner(this: Self) -> &'static T {
|
|
|
|
|
this.inner
|
|
|
|
|
}
|
|
|
|
|
pub fn get_ref(this: &Self) -> &C::InternedImpl<T> {
|
|
|
|
|
pub fn get_ref(this: &Self) -> &&'static T {
|
|
|
|
|
&this.inner
|
|
|
|
|
}
|
|
|
|
|
pub fn guard(&self) -> Guard<T, C> {
|
|
|
|
|
Guard {
|
|
|
|
|
inner: C::guard(&self.inner),
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Clone for Interned<T, C> {
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync> Clone for Interned<T> {
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
Interned {
|
|
|
|
|
inner: self.inner.clone(),
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
*self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Copy for Interned<T, C> where
|
|
|
|
|
C::InternedImpl<T>: Copy
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync> Copy for Interned<T> where &'static T: Copy {}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Deref for Interned<T, C>
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync> Deref for Interned<T>
|
|
|
|
|
where
|
|
|
|
|
C::InternedImpl<T>: Borrow<T>,
|
|
|
|
|
&'static T: Borrow<T>,
|
|
|
|
|
{
|
|
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
|
self.inner.borrow()
|
|
|
|
|
self.inner
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> PartialEq
|
|
|
|
|
for Interned<T, C>
|
|
|
|
|
{
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare> PartialEq for Interned<T> {
|
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
|
<C as InternContext>::interned_compare_key(&self.inner)
|
|
|
|
|
== <C as InternContext>::interned_compare_key(&other.inner)
|
|
|
|
|
T::interned_compare_key_ref(self.inner) == T::interned_compare_key_ref(other.inner)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> Eq for Interned<T, C> {}
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare> Eq for Interned<T> {}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> PartialOrd
|
|
|
|
|
for Interned<T, C>
|
|
|
|
|
{
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare> PartialOrd for Interned<T> {
|
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
|
|
|
Some(self.cmp(other))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> Ord for Interned<T, C> {
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare> Ord for Interned<T> {
|
|
|
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
|
|
|
|
<C as InternContext>::interned_compare_key(&self.inner)
|
|
|
|
|
.cmp(&<C as InternContext>::interned_compare_key(&other.inner))
|
|
|
|
|
T::interned_compare_key_ref(self.inner).cmp(&T::interned_compare_key_ref(other.inner))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> Hash
|
|
|
|
|
for Interned<T, C>
|
|
|
|
|
{
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare> Hash for Interned<T> {
|
|
|
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
|
|
|
<C as InternContext>::interned_compare_key(&self.inner).hash(state);
|
|
|
|
|
T::interned_compare_key_ref(self.inner).hash(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + Serialize, C: InternContext> Serialize for Interned<T, C> {
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + Serialize> Serialize for Interned<T> {
|
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
|
where
|
|
|
|
|
S: serde::Serializer,
|
|
|
|
|
{
|
|
|
|
|
self.guard().serialize(serializer)
|
|
|
|
|
T::serialize(self, serializer)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<
|
|
|
|
|
'de,
|
|
|
|
|
T: 'static + Send + Sync + Deserialize<'de> + Clone + Intern<C>,
|
|
|
|
|
C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default,
|
|
|
|
|
> Deserialize<'de> for Interned<T, C>
|
|
|
|
|
impl<'de, T: 'static + Send + Sync + Deserialize<'de> + Clone + Intern> Deserialize<'de>
|
|
|
|
|
for Interned<T>
|
|
|
|
|
{
|
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
|
|
where
|
|
|
|
@ -809,13 +616,9 @@ impl<
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<
|
|
|
|
|
'de,
|
|
|
|
|
T: 'static + Send + Sync + Clone,
|
|
|
|
|
C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default,
|
|
|
|
|
> Deserialize<'de> for Interned<[T], C>
|
|
|
|
|
impl<'de, T: 'static + Send + Sync + Clone> Deserialize<'de> for Interned<[T]>
|
|
|
|
|
where
|
|
|
|
|
[T]: Intern<C>,
|
|
|
|
|
[T]: Intern,
|
|
|
|
|
Vec<T>: Deserialize<'de>,
|
|
|
|
|
{
|
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
|
@ -826,11 +629,7 @@ where
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'de, C: BitSliceInternContext<AllContextsAreIdentical = ConstBool<true>> + Default>
|
|
|
|
|
Deserialize<'de> for Interned<BitSlice, C>
|
|
|
|
|
where
|
|
|
|
|
BitSlice: Intern<C>,
|
|
|
|
|
{
|
|
|
|
|
impl<'de> Deserialize<'de> for Interned<BitSlice> {
|
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
|
|
where
|
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
@ -839,11 +638,7 @@ where
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'de, C: InternContext<AllContextsAreIdentical = ConstBool<true>> + Default> Deserialize<'de>
|
|
|
|
|
for Interned<str, C>
|
|
|
|
|
where
|
|
|
|
|
str: Intern<C>,
|
|
|
|
|
{
|
|
|
|
|
impl<'de> Deserialize<'de> for Interned<str> {
|
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
|
|
where
|
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
@ -852,175 +647,83 @@ where
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Guard<T: ?Sized + 'static + Send + Sync, C: InternContext = GlobalContext> {
|
|
|
|
|
inner: C::InternedGuardImpl<T>,
|
|
|
|
|
_phantom: PhantomData<&'static C>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Guard<T, C> {
|
|
|
|
|
pub fn cast_unchecked<U: ?Sized + 'static + Send + Sync>(
|
|
|
|
|
this: Self,
|
|
|
|
|
f: impl FnOnce(C::InternedGuardImpl<T>) -> C::InternedGuardImpl<U>,
|
|
|
|
|
) -> Guard<U, C> {
|
|
|
|
|
Guard {
|
|
|
|
|
inner: f(this.inner),
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn try_cast_unchecked<U: ?Sized + 'static + Send + Sync, E>(
|
|
|
|
|
this: Self,
|
|
|
|
|
f: impl FnOnce(C::InternedGuardImpl<T>) -> Result<C::InternedGuardImpl<U>, E>,
|
|
|
|
|
) -> Result<Guard<U, C>, E> {
|
|
|
|
|
Ok(Guard {
|
|
|
|
|
inner: f(this.inner)?,
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
pub fn into_inner(this: Self) -> C::InternedGuardImpl<T> {
|
|
|
|
|
this.inner
|
|
|
|
|
}
|
|
|
|
|
pub fn get_ref(this: &Self) -> &C::InternedGuardImpl<T> {
|
|
|
|
|
&this.inner
|
|
|
|
|
}
|
|
|
|
|
pub fn unguard(&self) -> Interned<T, C> {
|
|
|
|
|
Interned {
|
|
|
|
|
inner: C::unguard(&self.inner),
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Clone for Guard<T, C> {
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
Guard {
|
|
|
|
|
inner: self.inner.clone(),
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Copy for Guard<T, C> where
|
|
|
|
|
C::InternedGuardImpl<T>: Copy
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync, C: InternContext> Deref for Guard<T, C> {
|
|
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
|
self.inner.borrow()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> PartialEq
|
|
|
|
|
for Guard<T, C>
|
|
|
|
|
{
|
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
|
T::interned_compare_key_ref(self.inner.borrow())
|
|
|
|
|
== T::interned_compare_key_ref(other.inner.borrow())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> Eq for Guard<T, C> {}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> PartialOrd
|
|
|
|
|
for Guard<T, C>
|
|
|
|
|
{
|
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
|
|
|
Some(self.cmp(other))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> Ord for Guard<T, C> {
|
|
|
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
|
|
|
|
T::interned_compare_key_ref(self.inner.borrow())
|
|
|
|
|
.cmp(&T::interned_compare_key_ref(other.inner.borrow()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: ?Sized + 'static + Send + Sync + InternedCompare, C: InternContext> Hash for Guard<T, C> {
|
|
|
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
|
|
|
T::interned_compare_key_ref(self.inner.borrow()).hash(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + Send + Sync + 'static + Hash + Eq, C: InternContext> Intern<C> for T {
|
|
|
|
|
fn intern_with_ctx(&self, context: &C) -> Interned<Self, C> {
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Borrowed(self), context)
|
|
|
|
|
impl<T: Clone + Send + Sync + 'static + Hash + Eq> Intern for T {
|
|
|
|
|
fn intern(&self) -> Interned<Self> {
|
|
|
|
|
Self::intern_cow(Cow::Borrowed(self))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_owned_with_ctx(this: <Self as ToOwned>::Owned, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_owned(this: <Self as ToOwned>::Owned) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Owned(this), context)
|
|
|
|
|
Self::intern_cow(Cow::Owned(this))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_cow_with_ctx(this: Cow<'_, Self>, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_cow(this: Cow<'_, Self>) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
context.interner().intern_sized(context, this)
|
|
|
|
|
Interner::get().intern_sized(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Clone + Send + Sync + 'static + Hash + Eq, C: InternContext> Intern<C> for [T] {
|
|
|
|
|
fn intern_with_ctx(&self, context: &C) -> Interned<Self, C> {
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Borrowed(self), context)
|
|
|
|
|
impl<T: Clone + Send + Sync + 'static + Hash + Eq> Intern for [T] {
|
|
|
|
|
fn intern(&self) -> Interned<Self> {
|
|
|
|
|
Self::intern_cow(Cow::Borrowed(self))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_owned_with_ctx(this: <Self as ToOwned>::Owned, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_owned(this: <Self as ToOwned>::Owned) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Owned(this), context)
|
|
|
|
|
Self::intern_cow(Cow::Owned(this))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_cow_with_ctx(this: Cow<'_, Self>, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_cow(this: Cow<'_, Self>) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
context.interner().intern_slice(context, this)
|
|
|
|
|
Interner::get().intern_slice(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<C: BitSliceInternContext> Intern<C> for BitSlice {
|
|
|
|
|
fn intern_with_ctx(&self, context: &C) -> Interned<Self, C> {
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Borrowed(self), context)
|
|
|
|
|
impl Intern for BitSlice {
|
|
|
|
|
fn intern(&self) -> Interned<Self> {
|
|
|
|
|
Self::intern_cow(Cow::Borrowed(self))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_owned_with_ctx(this: <Self as ToOwned>::Owned, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_owned(this: <Self as ToOwned>::Owned) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Owned(this), context)
|
|
|
|
|
Self::intern_cow(Cow::Owned(this))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_cow_with_ctx(this: Cow<'_, Self>, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_cow(this: Cow<'_, Self>) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
context.interner().intern_bit_slice(context, this)
|
|
|
|
|
Interner::get().intern_bit_slice(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<C: InternContext> Intern<C> for str {
|
|
|
|
|
fn intern_with_ctx(&self, context: &C) -> Interned<Self, C> {
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Borrowed(self), context)
|
|
|
|
|
impl Intern for str {
|
|
|
|
|
fn intern(&self) -> Interned<Self> {
|
|
|
|
|
Self::intern_cow(Cow::Borrowed(self))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_owned_with_ctx(this: <Self as ToOwned>::Owned, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_owned(this: <Self as ToOwned>::Owned) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
Self::intern_cow_with_ctx(Cow::Owned(this), context)
|
|
|
|
|
Self::intern_cow(Cow::Owned(this))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn intern_cow_with_ctx(this: Cow<'_, Self>, context: &C) -> Interned<Self, C>
|
|
|
|
|
fn intern_cow(this: Cow<'_, Self>) -> Interned<Self>
|
|
|
|
|
where
|
|
|
|
|
Self: ToOwned,
|
|
|
|
|
{
|
|
|
|
|
context.interner().intern_str(context, this)
|
|
|
|
|
Interner::get().intern_str(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|