//! Contains `Collapse` impls for primitive types through a newtime wrapper.
//!
//! Contains `Collapse` impls for primitive types through a newtime shim.
//!
//! # Why
//! Such wrappers are a workaround for the lack of template specialisation available in Rust so far, as the generic `impl<T: Hash> Collapse<T> for T` still requires computing the hash of the internal types before reducing to the `u8` page index.
//! For primitive types, this is unnessisary and causes a (very slight) performance loss.
//!
//! If/when Rust gets specialisation, this will be unneeded.
usesuper::*;
usestd::num::*;
/// Sealed trait allowing for wrapping primitive types with a more efficient implemntation for the `Collapse` trait.
/// This should not be used for much directly, instead use the newtype shim `Primitive<T>`.
pubtraitPrimitiveCollapse: private::Sealed
{
fncollapse(&self)-> u8;
}
/// Shim for primitive types to efficiently implement `Collapse`.
///
/// # Notes
/// This newtype is transparent. It is safe to `mem::transmute`() from `Primitive<T>` to `T` and vice versa.
/// However, if `T` does *not* implement `PrimitiveCollapse`, it is undefined behaviour.
///
/// Also, the `collapse()` output from this structure is not guaranteed to be the same as the `collapse()` output from the inner value, so the following code is very unsafe and such patterns should only be used if the programmer is absolutely sure there will be absolutely no difference between `T::collapse` and `Self::collapse`:
/// ```
/// # use smallmap::{Map, Primitive};
/// # use std::mem;
///
/// let mut map: Map<u8, ()> = Map::new();
/// map.insert(120, ());
///
/// let map: Map<Primitive<u8>, ()> = unsafe { mem::transmute(map) };
/// Only useful if the inner type does not implement `Copy`, which is extremely unlickely.
/// You should almost always use `into_inner` instead.
#[inline]pubfninner(&self)-> &T
{
&self.0
}
/// Get a mutable reference to the inner ptimitive.
#[inline]pubfninner_mut(&mutself)-> &mutT
{
&mutself.0
}
#[const_fn]
#[inline]pubconstfncopy_into_inner(&self)-> T
/// Same as `into_inner`, except only for `Copy` types.
///
/// # Notes
/// The only use of this function is that it is `const fn` on nightly.
/// If you're not using a version of rustc that supports generic `const fn`, this method is identical to `into_inner`.
#[cfg(nightly)]#[inline]pubconstfninto_inner_copy(self)-> T
whereT: Copy
{
self.0
}
#[cfg(not(nightly))]#[inline(always)]#[deprecated = "This function should only be used on Rust nightly. Please use `into_inner` instead"]pubfninto_inner_copy(self)-> T
//! To make an entirely space efficient `Map` (i.e. size of each page is 256 bytes, there is never more than 1 page), the following must be true:
//!
//! * The key must be 8 bits wide and subject to the *null pointer optimisation*
//! * The value must be a ZST.
//!
//! This leaves pretty much only `NonZeroU8` and `NonZeroI8` as entirely space-efficient key candidates.
//! The restriction on values also means the only entirely space-efficient smallmaps are sets, enable to encode only if a key is present, with no extra information. (See `std::collections::HashSet`).
usesuper::*;
/// A set of only non-zero bytes.
///
/// This type is entirely space efficient and will only ever allocate `256` bytes of memory.