Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Self-Referential Buffer Example

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

// Copyright 2026 Google LLC
// SPDX-License-Identifier: Apache-2.0

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 分鐘
Definition of Pin5 分鐘
PhantomPinned5 分鐘
Self-Referential Buffer Example50 分鐘
Pin and Drop15 分鐘