Skip to content

Commit

Permalink
Re-remove Interned::of_default following review
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Aug 29, 2024
1 parent 547bd68 commit b96698b
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions crates/circuit/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,6 @@ impl<T: ?Sized> Copy for Interned<T> {}
unsafe impl<T: ?Sized> Send for Interned<T> {}
unsafe impl<T: ?Sized> Sync for Interned<T> {}

impl<T> Interned<T>
where
T: ?Sized + ToOwned,
<T as ToOwned>::Owned: Default,
{
/// Get the interned key of the default value for the interned type. The interner of a type
/// with a default value always includes a statically known key that is valid for the default,
/// so this is safe to construct even in the absence of an actual interner.
///
/// # Examples
///
/// ```rust
/// # use crate::interner::{Interner, Interned};
/// let interner = Interner<[usize]>;
/// assert_eq!(interner.get(Interned::of_default()), &[]);
/// ```
#[inline(always)]
pub fn of_default() -> Self {
Self {
index: 0,
_type: PhantomData,
}
}
}

/// An append-only data structure for interning generic Rust types.
///
/// The interner can lookup keys using a reference type, and will create the corresponding owned
Expand Down Expand Up @@ -140,14 +115,15 @@ where
/// slice `&[]`. This is a common operation with the cargs interner, for things like pushing
/// gates.
///
/// This can also be retrieved without a reference to an interner by `Interned::of_default`.
///
/// In an ideal world, we wouldn't have the `Default` trait bound on `new`, but would use
/// specialisation to insert the default key only if the stored value implemented `Default`
/// (we'd still trait-bound this method).
#[inline(always)]
pub fn get_default(&self) -> Interned<T> {
Interned::of_default()
Interned {
index: 0,
_type: PhantomData,
}
}
}

Expand Down

0 comments on commit b96698b

Please sign in to comment.