Skip to content

Commit

Permalink
pub more rawlist api
Browse files Browse the repository at this point in the history
Signed-off-by: guoweikang <[email protected]>
  • Loading branch information
guoweikang committed Oct 24, 2024
1 parent c1fe2c8 commit ed4575e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

mod linked_list;
mod raw_list;
pub use linked_list::List;
pub use linked_list::{List, Wrapper};
pub use raw_list::{GetLinks, Links, RawList};

#[macro_export(local_inner_macros)]
Expand Down
12 changes: 6 additions & 6 deletions src/raw_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,42 +370,42 @@ impl<'a, G: GetLinks> CursorMut<'a, G> {
}
}

pub(crate) fn current(&mut self) -> Option<&mut G::EntryType> {
pub fn current(&mut self) -> Option<&mut G::EntryType> {
let cur = self.cursor.cur?;
// SAFETY: Objects must be kept alive while on the list.
Some(unsafe { &mut *cur.as_ptr() })
}

/// Removes the entry the cursor is pointing to and advances the cursor to the next entry. It
/// returns a raw pointer to the removed element (if one is removed).
pub(crate) fn remove_current(&mut self) -> Option<NonNull<G::EntryType>> {
pub fn remove_current(&mut self) -> Option<NonNull<G::EntryType>> {
let entry = self.cursor.cur?;
self.cursor.move_next(self.list);
// SAFETY: The entry is on the list as we just got it from there and it cannot change.
unsafe { self.list.remove(entry.as_ref()) };
Some(entry)
}

pub(crate) fn peek_next(&mut self) -> Option<&mut G::EntryType> {
pub fn peek_next(&mut self) -> Option<&mut G::EntryType> {
let mut new = CommonCursor::new(self.cursor.cur);
new.move_next(self.list);
// SAFETY: Objects must be kept alive while on the list.
Some(unsafe { &mut *new.cur?.as_ptr() })
}

pub(crate) fn peek_prev(&mut self) -> Option<&mut G::EntryType> {
pub fn peek_prev(&mut self) -> Option<&mut G::EntryType> {
let mut new = CommonCursor::new(self.cursor.cur);
new.move_prev(self.list);
// SAFETY: Objects must be kept alive while on the list.
Some(unsafe { &mut *new.cur?.as_ptr() })
}

pub(crate) fn move_next(&mut self) {
pub fn move_next(&mut self) {
self.cursor.move_next(self.list);
}

#[allow(dead_code)]
pub(crate) fn move_prev(&mut self) {
pub fn move_prev(&mut self) {
self.cursor.move_prev(self.list);
}
}
Expand Down

0 comments on commit ed4575e

Please sign in to comment.