@@ -73,6 +73,11 @@ pub struct GcVec<'gc, T: GcSafe, Ctx: GcSimpleAlloc> {
73
73
pub raw : GcRawVec < ' gc , T , Ctx :: Id >
74
74
}
75
75
impl < ' gc , T : GcSafe , Ctx : GcSimpleAlloc > GcVec < ' gc , T , Ctx > {
76
+ /// Convert this vector into its underlying [GcRawVec]
77
+ #[ inline]
78
+ pub fn into_raw ( self ) -> GcRawVec < ' gc , T , Ctx :: Id > {
79
+ self . raw
80
+ }
76
81
/// Reserve enough capacity for the specified number of additional elements.
77
82
#[ inline]
78
83
pub fn reserve ( & mut self , amount : usize ) {
@@ -81,6 +86,17 @@ impl<'gc, T: GcSafe, Ctx: GcSimpleAlloc> GcVec<'gc, T, Ctx> {
81
86
self . grow ( amount) ;
82
87
}
83
88
}
89
+ /// Extend the vector with elements copied from the specified slice
90
+ #[ inline]
91
+ pub fn extend_from_slice ( & mut self , src : & [ T ] )
92
+ where T : Copy {
93
+ self . reserve ( src. len ( ) ) ;
94
+ // TODO: Write barriers?
95
+ unsafe {
96
+ ( self . raw . as_repr_mut ( ) . ptr ( ) as * mut T ) . add ( self . len ( ) )
97
+ . copy_from_nonoverlapping ( src. as_ptr ( ) , src. len ( ) )
98
+ }
99
+ }
84
100
/// Push the specified value onto the vector
85
101
#[ inline]
86
102
pub fn push ( & mut self , val : T ) {
@@ -116,17 +132,17 @@ unsafe_gc_impl!(
116
132
params => [ ' gc, T : GcSafe , Ctx : GcSimpleAlloc ] ,
117
133
bounds => {
118
134
TraceImmutable => never,
119
- GcRebrand => { where T : GcRebrand <' new_gc, Ctx :: Id > } ,
120
- GcErase => { where T : GcErase <' min, Ctx :: Id > } ,
135
+ Trace => { where T : GcSafe } ,
136
+ GcRebrand => never,
137
+ GcErase => never,
121
138
} ,
122
- branded_type => <T as GcRebrand <' new_gc, Ctx :: Id >>:: Branded ,
123
- erased_type => <T as GcErase <' min, Ctx :: Id >>:: Erased ,
124
139
null_trace => never,
125
140
NEEDS_TRACE => true ,
126
141
NEEDS_DROP => T :: NEEDS_DROP /* if our inner type needs a drop */ ,
127
142
trace_mut => |self , visitor| {
128
143
unsafe { visitor. visit_vec:: <T , _>( self . raw. as_repr_mut( ) ) }
129
144
} ,
145
+ collector_id => Ctx :: Id
130
146
) ;
131
147
impl < ' gc , T : GcSafe , Ctx : GcSimpleAlloc > Deref for GcVec < ' gc , T , Ctx > {
132
148
type Target = GcRawVec < ' gc , T , Ctx :: Id > ;
@@ -308,11 +324,17 @@ unsafe_gc_impl!(
308
324
collector_id => Id ,
309
325
bounds => {
310
326
TraceImmutable => never,
311
- GcRebrand => { where T : GcRebrand <' new_gc, Id > } ,
312
- GcErase => { where T : GcErase <' min, Id > } ,
327
+ GcRebrand => {
328
+ where T : GcSafe + GcRebrand <' new_gc, Id >,
329
+ <T as GcRebrand <' new_gc, Id >>:: Branded : GcSafe
330
+ } ,
331
+ GcErase => {
332
+ where T : GcSafe + GcErase <' min, Id >,
333
+ <T as GcErase <' min, Id >>:: Erased : GcSafe
334
+ } ,
313
335
} ,
314
- branded_type => < T as GcRebrand <' new_gc, Id >>:: Branded ,
315
- erased_type => < T as GcErase <' min, Id >>:: Erased ,
336
+ branded_type => GcRawVec < ' new_gc , < T as GcRebrand <' new_gc, Id >>:: Branded , Id > ,
337
+ erased_type => GcRawVec < ' min , < T as GcErase <' min, Id >>:: Erased , Id > ,
316
338
null_trace => never,
317
339
NEEDS_TRACE => true ,
318
340
NEEDS_DROP => T :: NEEDS_DROP /* if our inner type needs a drop */ ,
0 commit comments