Skip to content

Instantly share code, notes, and snippets.

@kyren
kyren / freeze.rs
Created October 17, 2023 00:59
Freeze
use std::{cell::RefCell, marker::PhantomData, mem, rc::Rc};
use thiserror::Error;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Error)]
pub enum AccessError {
#[error("frozen value accessed outside of enclosing scope")]
Expired,
#[error("already borrowed incompatibly")]
BadBorrow,
use std::{iter, slice, vec};
use std::iter::FromIterator;
/// A unique identifier with an associated usize index. Indexes are valued proportional to the
/// number of indexes allocated, are reused after being freed, and do not grow without bound. When
/// an index is re-used, an associated "generation" is incremented, so that within the life of a
/// single allocator, no two GenerationalIndex values will ever be equal. Since the indexes do not
/// grow without bound, GenerationalIndex values are particularly suited to being stored by their
/// index in extremely fast contiguous arrays.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]