aiscript_arena/
static_collect.rs1use crate::Rootable;
2use crate::collect::Collect;
3
4use alloc::borrow::{Borrow, BorrowMut};
5use core::convert::{AsMut, AsRef};
6use core::ops::{Deref, DerefMut};
7
8#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
11#[repr(transparent)]
12pub struct Static<T: ?Sized>(pub T);
13
14impl<T: ?Sized + 'static> Rootable<'_> for Static<T> {
15 type Root = Static<T>;
16}
17
18unsafe impl<T: ?Sized + 'static> Collect for Static<T> {
19 #[inline]
20 fn needs_trace() -> bool {
21 false
22 }
23}
24
25impl<T> From<T> for Static<T> {
26 fn from(value: T) -> Self {
27 Self(value)
28 }
29}
30
31impl<T: ?Sized> AsRef<T> for Static<T> {
32 fn as_ref(&self) -> &T {
33 &self.0
34 }
35}
36
37impl<T: ?Sized> AsMut<T> for Static<T> {
38 fn as_mut(&mut self) -> &mut T {
39 &mut self.0
40 }
41}
42
43impl<T: ?Sized> Deref for Static<T> {
44 type Target = T;
45 fn deref(&self) -> &Self::Target {
46 &self.0
47 }
48}
49
50impl<T: ?Sized> DerefMut for Static<T> {
51 fn deref_mut(&mut self) -> &mut Self::Target {
52 &mut self.0
53 }
54}
55
56impl<T: ?Sized> Borrow<T> for Static<T> {
57 fn borrow(&self) -> &T {
58 &self.0
59 }
60}
61
62impl<T: ?Sized> BorrowMut<T> for Static<T> {
63 fn borrow_mut(&mut self) -> &mut T {
64 &mut self.0
65 }
66}