1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use core::cell::RefCell;
use inherent::inherent;
use crate::SimpleAllocCollectorId;
use crate::vec::raw::{IGcVec, ReallocFailedError};
use crate::prelude::*;
#[derive(Trace)]
#[zerogc(collector_ids(Id), copy)]
pub struct GcVecCell<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> {
inner: Gc<'gc, RefCell<GcVec<'gc, T, Id>>, Id>,
}
impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> GcVecCell<'gc, T, Id> {
#[inline]
pub fn borrow(&self) -> core::cell::Ref<'_, GcVec<'gc, T, Id>> {
self.inner.borrow()
}
#[inline]
pub fn borrow_mut(&self) -> core::cell::RefMut<'_, GcVec<'gc, T, Id>> {
self.inner.borrow_mut()
}
#[inline]
pub fn borrow_slice(&self) -> core::cell::Ref<'_, [T]> {
core::cell::Ref::map(self.borrow(), |v| v.as_slice())
}
#[inline]
pub fn borrow_mut_slice(&self) -> core::cell::RefMut<'_, [T]> {
core::cell::RefMut::map(self.borrow_mut(), |v| v.as_mut_slice())
}
}
impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> Copy for GcVecCell<'gc, T, Id> {}
impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> Clone for GcVecCell<'gc, T, Id> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> !Send for GcVecCell<'gc, T, Id> {}
#[inherent]
unsafe impl<'gc, T: GcSafe<'gc, Id>, Id: SimpleAllocCollectorId> IGcVec<'gc, T> for GcVecCell<'gc, T, Id> {
type Id = Id;
#[inline]
pub fn with_capacity_in(capacity: usize, ctx: &'gc <Id as CollectorId>::Context) -> Self {
GcVecCell { inner: ctx.alloc(RefCell::new(GcVec::with_capacity_in(capacity, ctx))) }
}
#[inline]
pub fn len(&self) -> usize {
self.inner.borrow().len()
}
#[inline]
pub unsafe fn set_len(&mut self, len: usize) {
self.inner.borrow_mut().set_len(len);
}
#[inline]
pub fn capacity(&self) -> usize {
self.inner.borrow().capacity()
}
#[inline]
pub fn reserve_in_place(&mut self, additional: usize) -> Result<(), ReallocFailedError> {
self.inner.borrow_mut().reserve_in_place(additional)
}
#[inline]
pub unsafe fn as_ptr(&self) -> *const T {
self.inner.borrow().as_ptr()
}
#[inline]
pub fn context(&self) -> &'gc <Id as CollectorId>::Context {
self.inner.borrow().context()
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut T;
pub fn replace(&mut self, index: usize, val: T) -> T;
pub fn set(&mut self, index: usize, val: T);
pub fn extend_from_slice(&mut self, src: &[T])
where T: Copy;
pub fn push(&mut self, val: T);
pub fn pop(&mut self) -> Option<T>;
pub fn swap_remove(&mut self, index: usize) -> T;
pub fn reserve(&mut self, additional: usize);
pub fn is_empty(&self) -> bool;
pub fn new_in(ctx: &'gc <Id as CollectorId>::Context) -> Self;
pub fn copy_from_slice(src: &[T], ctx: &'gc <Id as CollectorId>::Context) -> Self
where T: Copy;
pub fn from_vec(src: Vec<T>, ctx: &'gc <Id as CollectorId>::Context) -> Self;
pub fn get(&mut self, index: usize) -> Option<T>
where T: Copy;
pub unsafe fn as_slice_unchecked(&self) -> &[T];
}
impl<'gc, T: GcSafe<'gc, Id>, Id: CollectorId> Extend<T> for GcVecCell<'gc, T, Id> {
fn extend<A: IntoIterator<Item=T>>(&mut self, iter: A) {
self.inner.borrow_mut().extend(iter);
}
}