Skip to main content

DListItem

Trait DListItem 

Source
pub unsafe trait DListItem<Tag>: Sized {
    // Required method
    fn get_node(&self) -> &mut DListNode<Tag>;

    // Provided method
    unsafe fn get_node_from_ptr<'a>(p: *mut u8) -> &'a mut DListNode<Tag>
       where Self: 'a { ... }
}
Expand description

A trait to return internal mutable DListNode for specified list.

The tag is used to distinguish different DListNodes within the same item, allowing an item to belong to multiple lists simultaneously. For only one ownership, you can use ().

§Safety

Implementors must ensure get_node returns a valid reference to the DListNode embedded within Self. Users must use UnsafeCell to hold DListNode to support interior mutability required by list operations.

Required Methods§

Source

fn get_node(&self) -> &mut DListNode<Tag>

Provided Methods§

Source

unsafe fn get_node_from_ptr<'a>(p: *mut u8) -> &'a mut DListNode<Tag>
where Self: 'a,

§Safety

This is just map from raw pointer to &mut DListNode.

You only have to implement this when using custom pointer type with abnormal address. Refer to Mixed Type Example

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§