This commit is contained in:
Adam Ierymenko 2022-10-21 16:51:49 -07:00
parent cf7f0b06df
commit ac9bac6efd
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3

View file

@ -4,15 +4,15 @@ use std::any::TypeId;
use std::mem::{forget, size_of, MaybeUninit}; use std::mem::{forget, size_of, MaybeUninit};
use std::ptr::{drop_in_place, read, write}; use std::ptr::{drop_in_place, read, write};
/// A statically sized container that acts a bit like Box<dyn Any>. /// A statically sized container that acts a bit like Box<dyn Any> but with less overhead.
/// ///
/// This is used in a few places to avoid cascades of templates by allowing templated /// This is used in a few places to avoid cascades of templates by allowing templated
/// objects to be held generically and accessed only within templated functions. It does so /// objects to be held generically and accessed only within templated functions. There's a
/// with very low to zero runtime overhead or memory overhead and panics if misused. /// bit of unsafe here but externally it's safe and panics if misused.
/// ///
/// This will panic if the capacity is too small. If that occurs, it must be enlarged. It will /// This will panic if the capacity is too small. If that occurs, it must be enlarged. It will
/// also panic if any of the accessors (other than the try_ versions) are used to try to get /// also panic if any of the accessors (other than the try_ versions) are used to try to get
/// a type other than the one it was /// a type other than the one it was constructed with.
pub struct Pocket<const CAPACITY: usize> { pub struct Pocket<const CAPACITY: usize> {
storage: [u8; CAPACITY], storage: [u8; CAPACITY],
dropper: fn(*mut u8), dropper: fn(*mut u8),