src/unsafe-deep-dive/pinning/self-referential-buffer/rust.md
# // Copyright 2026 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
/// Raw pointers
pub struct SelfReferentialBuffer {
data: [u8; 1024],
cursor: *mut u8,
}
/// Integer offsets
pub struct SelfReferentialBuffer {
data: [u8; 1024],
cursor: usize,
}
/// Pinning
pub struct SelfReferentialBuffer {
data: [u8; 1024],
cursor: *mut u8,
_pin: std::marker::PhantomPinned,
}
class SelfReferentialBuffer {
char data[1024];
char* cursor;
};
The next few slides show three approaches to creating a Rust type with the same semantics as the original C++.
unsafe blocks