Skip to main content

grafix_toolbox/kit/policies/
types.rs

1pub mod lazy {
2	pub use super::{arc_slice::*, cached::*, cached_str::*, feed::*, lazy_cell::*, memoized::MemRes, memoized::Memoized, prefetch::*, ver_vec::*};
3}
4
5pub type STR = &'static str;
6pub type Str = Box<str>;
7pub type Astr = Arc<str>;
8
9#[inline(always)]
10pub fn Arc<T>(v: T) -> Arc<T> {
11	Arc::new(v)
12}
13#[inline(always)]
14pub fn Box<T>(v: T) -> Box<T> {
15	Box::new(v)
16}
17#[inline(always)]
18pub fn Cell<T>(v: T) -> Cell<T> {
19	Cell::new(v)
20}
21#[inline(always)]
22pub fn Def<T: Default>() -> T {
23	<_>::default()
24}
25
26pub trait MutateCell<'i, T: 'i> {
27	fn mutate<R: Default>(&self, with: impl FnOnce(&'i mut T) -> R) -> R;
28}
29impl<'i, T: 'i> MutateCell<'i, T> for Cell<T> {
30	#[inline(always)]
31	fn mutate<R: Default>(&self, with: impl FnOnce(&'i mut T) -> R) -> R {
32		with(unsafe { &mut *self.as_ptr() })
33	}
34}
35
36pub trait InspectCell<'s, T> {
37	fn bind(&'s self) -> &'s T;
38}
39impl<'s, T> InspectCell<'s, T> for &'s Cell<T> {
40	#[inline(always)]
41	fn bind(&'s self) -> &'s T {
42		unsafe { &*self.as_ptr() }
43	}
44}
45impl<'s, T> InspectCell<'s, T> for &'s mut Cell<T> {
46	#[inline(always)]
47	fn bind(&'s self) -> &'s T {
48		unsafe { &*self.as_ptr() }
49	}
50}
51
52mod arc_slice;
53mod cached;
54mod cached_str;
55mod feed;
56mod lazy_cell;
57mod memoized;
58mod prefetch;
59mod ver_vec;
60
61use std::{cell::Cell, sync::Arc};