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

Смоделировано на C++

#include <cstddef>
#include <cstring>

class SelfReferentialBuffer {
    std::byte data[1024];
    std::byte* cursor = data;
    
public:
    SelfReferentialBuffer(SelfReferentialBuffer&& other) 
        : cursor{data + (other.cursor - other.data)}
    {
        std::memcpy(data, other.data, 1024);
    }
};

Изучите на Compiler Explorer

SelfReferentialBuffer содержит два члена: data — килобайт памяти, а cursor — указатель внутрь первого.

Его конструктор перемещения гарантирует, что cursor обновляется до нового адреса в памяти.

Этот тип нелегко выразить в Rust.