@@ -90,21 +90,23 @@ impl<T: ?Sized> ListEntry<T> {
9090/// # Invariants
9191///
9292/// The links of objects added to a list are owned by the list.
93- pub ( crate ) struct RawList < G : GetLinks > {
93+ pub struct RawList < G : GetLinks > {
9494 head : Option < NonNull < G :: EntryType > > ,
9595}
9696
9797impl < G : GetLinks > RawList < G > {
98- pub ( crate ) const fn new ( ) -> Self {
98+ /// Constructs a new empty RawList.
99+ pub const fn new ( ) -> Self {
99100 Self { head : None }
100101 }
101102
102103 /// Returns an iterator for the list starting at the first entry.
103- pub ( crate ) fn iter ( & self ) -> Iterator < ' _ , G > {
104+ pub fn iter ( & self ) -> Iterator < ' _ , G > {
104105 Iterator :: new ( self . cursor_front ( ) , self . cursor_back ( ) )
105106 }
106107
107- pub ( crate ) const fn is_empty ( & self ) -> bool {
108+ /// Returns whether the RawList is empty.
109+ pub const fn is_empty ( & self ) -> bool {
108110 self . head . is_none ( )
109111 }
110112
@@ -135,11 +137,7 @@ impl<G: GetLinks> RawList<G> {
135137 /// # Safety
136138 ///
137139 /// Callers must ensure that `existing` points to a valid entry that is on the list.
138- pub ( crate ) unsafe fn insert_after (
139- & mut self ,
140- existing : & G :: EntryType ,
141- new : & G :: EntryType ,
142- ) -> bool {
140+ pub unsafe fn insert_after ( & mut self , existing : & G :: EntryType , new : & G :: EntryType ) -> bool {
143141 let links = G :: get_links ( new) ;
144142 if !links. acquire_for_insertion ( ) {
145143 // Nothing to do if already inserted.
@@ -180,11 +178,21 @@ impl<G: GetLinks> RawList<G> {
180178 true
181179 }
182180
183- pub ( crate ) unsafe fn push_back ( & mut self , new : & G :: EntryType ) -> bool {
181+ /// Adds the given object to the end (back) of the list.
182+ ///
183+ /// Rawlist will save the reference as node NonNull<ptr>.
184+ /// The caller must ensure the validity of the reference while it is on
185+ /// the linked list.
186+ pub unsafe fn push_back ( & mut self , new : & G :: EntryType ) -> bool {
184187 self . push_back_internal ( new, false )
185188 }
186189
187- pub ( crate ) unsafe fn push_front ( & mut self , new : & G :: EntryType ) -> bool {
190+ /// Adds the given object to the first (front) of the list.
191+ ///
192+ /// Rawlist will save the reference as node NonNull<ptr>.
193+ /// The caller must ensure the validity of the reference while it is on
194+ /// the linked list.
195+ pub unsafe fn push_front ( & mut self , new : & G :: EntryType ) -> bool {
188196 self . push_back_internal ( new, true )
189197 }
190198
@@ -232,7 +240,7 @@ impl<G: GetLinks> RawList<G> {
232240 ///
233241 /// Callers must ensure that `data` is either on this list or in no list. It being on another
234242 /// list leads to memory unsafety.
235- pub ( crate ) unsafe fn remove ( & mut self , data : & G :: EntryType ) -> bool {
243+ pub unsafe fn remove ( & mut self , data : & G :: EntryType ) -> bool {
236244 self . remove_internal ( data)
237245 }
238246
@@ -244,7 +252,7 @@ impl<G: GetLinks> RawList<G> {
244252 }
245253
246254 /// Get and Remove the first element of the list.
247- pub ( crate ) fn pop_front ( & mut self ) -> Option < NonNull < G :: EntryType > > {
255+ pub fn pop_front ( & mut self ) -> Option < NonNull < G :: EntryType > > {
248256 self . pop_front_internal ( )
249257 }
250258
@@ -270,7 +278,7 @@ impl<G: GetLinks> RawList<G> {
270278 }
271279
272280 /// Returns a mut cursor starting on the first element of the list.
273- pub ( crate ) fn cursor_front_mut ( & mut self ) -> CursorMut < ' _ , G > {
281+ pub fn cursor_front_mut ( & mut self ) -> CursorMut < ' _ , G > {
274282 CursorMut :: new ( self , self . front ( ) )
275283 }
276284}
@@ -361,7 +369,7 @@ impl<'a, G: GetLinks> Cursor<'a, G> {
361369 }
362370}
363371
364- pub ( crate ) struct CursorMut < ' a , G : GetLinks > {
372+ pub struct CursorMut < ' a , G : GetLinks > {
365373 cursor : CommonCursor < G > ,
366374 list : & ' a mut RawList < G > ,
367375}
@@ -374,42 +382,42 @@ impl<'a, G: GetLinks> CursorMut<'a, G> {
374382 }
375383 }
376384
377- pub ( crate ) fn current ( & mut self ) -> Option < & mut G :: EntryType > {
385+ pub fn current ( & mut self ) -> Option < & mut G :: EntryType > {
378386 let cur = self . cursor . cur ?;
379387 // SAFETY: Objects must be kept alive while on the list.
380388 Some ( unsafe { & mut * cur. as_ptr ( ) } )
381389 }
382390
383391 /// Removes the entry the cursor is pointing to and advances the cursor to the next entry. It
384392 /// returns a raw pointer to the removed element (if one is removed).
385- pub ( crate ) fn remove_current ( & mut self ) -> Option < NonNull < G :: EntryType > > {
393+ pub fn remove_current ( & mut self ) -> Option < NonNull < G :: EntryType > > {
386394 let entry = self . cursor . cur ?;
387395 self . cursor . move_next ( self . list ) ;
388396 // SAFETY: The entry is on the list as we just got it from there and it cannot change.
389397 unsafe { self . list . remove ( entry. as_ref ( ) ) } ;
390398 Some ( entry)
391399 }
392400
393- pub ( crate ) fn peek_next ( & mut self ) -> Option < & mut G :: EntryType > {
401+ pub fn peek_next ( & mut self ) -> Option < & mut G :: EntryType > {
394402 let mut new = CommonCursor :: new ( self . cursor . cur ) ;
395403 new. move_next ( self . list ) ;
396404 // SAFETY: Objects must be kept alive while on the list.
397405 Some ( unsafe { & mut * new. cur ?. as_ptr ( ) } )
398406 }
399407
400- pub ( crate ) fn peek_prev ( & mut self ) -> Option < & mut G :: EntryType > {
408+ pub fn peek_prev ( & mut self ) -> Option < & mut G :: EntryType > {
401409 let mut new = CommonCursor :: new ( self . cursor . cur ) ;
402410 new. move_prev ( self . list ) ;
403411 // SAFETY: Objects must be kept alive while on the list.
404412 Some ( unsafe { & mut * new. cur ?. as_ptr ( ) } )
405413 }
406414
407- pub ( crate ) fn move_next ( & mut self ) {
415+ pub fn move_next ( & mut self ) {
408416 self . cursor . move_next ( self . list ) ;
409417 }
410418
411419 #[ allow( dead_code) ]
412- pub ( crate ) fn move_prev ( & mut self ) {
420+ pub fn move_prev ( & mut self ) {
413421 self . cursor . move_prev ( self . list ) ;
414422 }
415423}
@@ -423,7 +431,7 @@ impl<'a, G: GetLinks> iter::IntoIterator for &'a RawList<G> {
423431}
424432
425433/// An iterator for the linked list.
426- pub ( crate ) struct Iterator < ' a , G : GetLinks > {
434+ pub struct Iterator < ' a , G : GetLinks > {
427435 cursor_front : Cursor < ' a , G > ,
428436 cursor_back : Cursor < ' a , G > ,
429437}
0 commit comments