Crate containerof

source ·
Expand description

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§

  • Implement C-like offsetof macro in Rust. Rust has stabilized ::std::mem::offset_of! since 1.77.0, you should use that, instead.
  • Define a type representing the translation between an intrusive field and its containing structure.

Structs§

  • 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.
  • 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.
  • 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.
  • 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§

  • 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.
  • 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 thecontainerof_intrusive!` macro.