Crate tiptoe

Source
Expand description

Generic intrusive smart pointers for Rust.

Zulip Chat

The library name is a pun:

TipToe is a digit (counter) to be used as member that instances can “balance” on.

The embedded counter is designed to be as unobtrusive as possible while not in use.

§Features

§"sync"

Enables the Arc type, which requires AtomicUsize.

§Example

§Implementing IntrusivelyCountable

use pin_project::pin_project;
use tiptoe::{IntrusivelyCountable, TipToe};

// All attributes optional.
#[pin_project]
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct A {
    #[pin]
    ref_counter: TipToe,
}

unsafe impl IntrusivelyCountable for A {
    type RefCounter = TipToe;

    fn ref_counter(&self) -> &Self::RefCounter {
        &self.ref_counter
    }
}

A is now ready for use with the intrusive pointers defined in this crate.

The derived traits are optional, but included to show that TipToe doesn’t interfere here (except for Copy).

Using pin-project is optional, but very helpful if a struct should still be otherwise(!) mutable behind an intrusive pointer.

Note that A must not be Unpin (in a way that would interfere with reference-counting).

Modules§

ref_counter_api
Low-level RefCounter API for custom intrusive reference-counting containers.

Structs§

Arc
An asynchronously reference-counted smart pointer (copy-on-write single-item container).
ExclusivePin
A Pin<&'a mut T>, but also guarding against handle clones.
TipToe
An embeddable strong-only reference counter.

Traits§

IntrusivelyCountable
Enables intrusive reference counting for a structure.
ManagedClone
Exactly like Clone but with safety restrictions regarding usage.
RefCounter
(Sealed) Common trait of tiptoe’s embeddable reference counter types.