@@ -229,6 +229,32 @@ impl Allocator {
229229 chunk_footer. ptr . get ( )
230230 }
231231
232+ /// Set cursor pointer for this [`Allocator`]'s current chunk.
233+ ///
234+ /// This is dangerous, and this method should not ordinarily be used.
235+ /// It is only here for manually resetting the allocator.
236+ ///
237+ /// # SAFETY
238+ ///
239+ /// * Allocator must have at least 1 allocated chunk.
240+ /// It is UB to call this method on an `Allocator` which has not allocated
241+ /// i.e. fresh from `Allocator::new`.
242+ /// * `ptr` must point to within the allocation underlying this allocator.
243+ /// * `ptr` must be after `data_ptr` for this chunk.
244+ pub unsafe fn set_cursor_ptr ( & self , ptr : NonNull < u8 > ) {
245+ // SAFETY: Caller guarantees `Allocator` has at least 1 allocated chunk.
246+ // We don't take any action with the `Allocator` while the `&mut ChunkFooter` reference
247+ // is alive, beyond setting the data pointer.
248+ let chunk_footer = unsafe { self . chunk_footer_mut ( ) } ;
249+ chunk_footer. ptr . set ( ptr) ;
250+ }
251+
252+ /// Get pointer to end of the data region of this [`Allocator`]'s current chunk
253+ /// i.e to the start of the `ChunkFooter`.
254+ pub fn data_end_ptr ( & self ) -> NonNull < u8 > {
255+ self . chunk_footer_ptr ( ) . cast :: < u8 > ( )
256+ }
257+
232258 /// Get pointer to end of this [`Allocator`]'s current chunk (after the `ChunkFooter`).
233259 pub fn end_ptr ( & self ) -> NonNull < u8 > {
234260 // SAFETY: `chunk_footer_ptr` returns pointer to a valid `ChunkFooter`,
0 commit comments