gc_arena/
static_collect.rs

1use crate::collect::Collect;
2
3use alloc::borrow::{Borrow, BorrowMut};
4use core::convert::{AsMut, AsRef};
5use core::ops::{Deref, DerefMut};
6
7/// A wrapper type that implements Collect whenever the contained T is 'static, which is useful in
8/// generic contexts
9#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
10#[repr(transparent)]
11pub struct StaticCollect<T>(pub T);
12
13unsafe impl<T: 'static> Collect for StaticCollect<T> {
14    #[inline]
15    fn needs_trace() -> bool {
16        false
17    }
18}
19
20impl<T> From<T> for StaticCollect<T> {
21    fn from(value: T) -> Self {
22        Self(value)
23    }
24}
25
26impl<T> AsRef<T> for StaticCollect<T> {
27    fn as_ref(&self) -> &T {
28        &self.0
29    }
30}
31impl<T> AsMut<T> for StaticCollect<T> {
32    fn as_mut(&mut self) -> &mut T {
33        &mut self.0
34    }
35}
36
37impl<T> Deref for StaticCollect<T> {
38    type Target = T;
39    fn deref(&self) -> &Self::Target {
40        &self.0
41    }
42}
43impl<T> DerefMut for StaticCollect<T> {
44    fn deref_mut(&mut self) -> &mut Self::Target {
45        &mut self.0
46    }
47}
48
49impl<T> Borrow<T> for StaticCollect<T> {
50    fn borrow(&self) -> &T {
51        &self.0
52    }
53}
54impl<T> BorrowMut<T> for StaticCollect<T> {
55    fn borrow_mut(&mut self) -> &mut T {
56        &mut self.0
57    }
58}