containerof 0.2.2

Macros and traits facilitating the use of intrusive structures in Rust.

Crate containerof [] [src]

Intrusive structure support in Rust.

An intrusive structure is a general-purpose structure directly embedded within a containing structure, in order to add that general-purpose facility to the container. As an example, one might use an intrusive "link" structure to allow objects to be organized in a linked-list:

Example

struct Link {
    next: Option<ContainerLink>,
}
struct List {
    head: Option<ContainerLink>,
    tail: Option<ContainerLink>,
}
 
struct Container {
    link: Link,
}
containerof_intrusive!(ContainerLink = Container:link::Link);

Macros

containerof_field_offset!

Implement C-like offsetof macro in Rust. Will become obsolete when-and-if offsetof() is implemented in the core language.

containerof_intrusive!

Define a type representing the translation between an intrusive field and its containing structure.

Structs

BorrowBox

A borrow-pointer that does not require explicit ownership of the value being borrowed. Used to allow construction of the Intrusive structure translation type from a borrow pointer.

BorrowBoxMut

A mutable borrow-pointer that does not require explicit ownership of the value being borrowed. Used to allow construction of the Intrusive structure translation type from a mutable borrow pointer.

IntrusiveAlias

Alias that has the same representation as an intrusive translation type. The idea is to be able to use this alias for intrusive facility implementations, by defining the "true" implementation of the facility to use the single (but type-unsafe) IntrusiveAlias type, while allowing type-safe wrapper implementations to delegate their behavior to the implementation function.

OwnBox

Represent ownership of an object via ownership of an intrusive field within the object. Differs from Rust-standard Box<T> in that dropping an OwnBox<T> instance is a bug.

Traits

Intrusive

Trait defining routines for translation between containing structure and intrusive field. The only implementors of this trait should be the translation-types defined by the containerof_intrusive! macro.

IntrusiveBase

Minimal trait that, when implemented for a type, allows for the blanket implementation of the Intrusive trait for that type. This is the trait implemented by the containerof_intrusive! macro, and the only implementors of this trait should be the translation-types defined by the containerof_intrusive! macro.