Interns a slice of values into the set. This method is similar to `intern` but works with slices. It ensures that only one copy of a slice with identical content exists in memory. # Type Constraints - `T` must be `Debug + Copy + Eq + Hash` - `T` must not be a zero-sized type - `T` must not implement `Drop` # Examples Basic usage: ``` # use hashql_core::{heap::Heap, intern::InternSet}; let he
(&self, value: &[T])
| 387 | /// let interned = interner.intern_slice(slice); |
| 388 | /// ``` |
| 389 | pub fn intern_slice(&self, value: &[T]) -> Interned<'heap, [T]> { |
| 390 | const { Self::ASSERT_T_IS_NOT_DROP }; |
| 391 | const { Self::ASSERT_T_IS_NOT_ZERO_SIZED }; |
| 392 | |
| 393 | if value.is_empty() { |
| 394 | return Interned::empty(); |
| 395 | } |
| 396 | |
| 397 | let heap = self.heap; |
| 398 | |
| 399 | let value = self.inner.map(|inner| { |
| 400 | let hash_value = inner.hasher().hash_one(value); |
| 401 | |
| 402 | match inner |
| 403 | .raw_entry_mut() |
| 404 | .from_key_hashed_nocheck(hash_value, value) |
| 405 | { |
| 406 | RawEntryMut::Vacant(entry) => { |
| 407 | let value = value.transfer_into(heap); |
| 408 | |
| 409 | let (key, ()) = entry.insert_hashed_nocheck(hash_value, &*value, ()); |
| 410 | *key |
| 411 | } |
| 412 | RawEntryMut::Occupied(entry) => *entry.key(), |
| 413 | } |
| 414 | }); |
| 415 | |
| 416 | Interned::new_unchecked(value) |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | #[cfg(test)] |