Self-Referential Buffer Example

A “self-referential buffer” is a type that has a reference to one of its own fields:

pub struct SelfReferentialBuffer {
    data: [u8; 1024],
    cursor: *mut u8,
}

This kind of structure is not typical in Rust, because there’s no way to update the cursor’s address when instances of SelfReferentialBuffer move.

However, this kind of setup is more natural in other languages that provide garbage collection, and also C++ that allows users to define their own behavior during moves and copies.

Outline

This segment should take about 1 hour and 20 minutes. It contains:

SlideDuration
What pinning is5 minutes
Definition of Pin5 minutes
PhantomPinned5 minutes
Self-Referential Buffer Example50 minutes
Pin and Drop15 minutes