Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }
Expand description

A window of cells, and a record of which shape decided each of them.

Every position in a freshly created buffer is undefined: it holds no cell until stamp is called for it. The buffer is a temporary working surface, not the document; there is no erase.

The record is kept beside the cells rather than inside one, in a map of its own, for the reason two cells that render alike must stay one cell: an identity inside a Cell would be a part of the cell rather than a note about who wrote it, and every equality, every render and every catalog lookup would then depend on it. owner reads the record back.

Implementations§

Source§

impl Buffer

Source

pub fn new(window: Window) -> Self

Creates a buffer with no positions defined, holding window.

A width or height of zero is allowed and gives a buffer with no positions; construction cannot fail.

Source

pub fn window(&self) -> Window

The window this buffer was created with.

A value rather than a borrow: a window is two small Copy values, and a caller that reads it while holding the buffer needs nothing back. What it is for is the translation an offset into the window needs and the size a rendering asks for.

Trait Implementations§

Source§

impl CellReader for Buffer

Source§

fn cell(&self, at: Pos) -> Option<&Cell>

The cell at the absolute position at, or None if it is undefined. Read more
Source§

impl OwnerReader for Buffer

Source§

fn owner(&self, at: Pos) -> Option<ShapeId>

The identity of whoever decided the cell at the position at, or None when nobody holds that position. Read more
Source§

impl StampSink for Buffer

Source§

fn stamp( &mut self, at: Pos, cell: Cell, mode: StampMode, owner: Option<ShapeId>, )

Writes cell at the absolute position at, under mode.

A position outside the window is left unchanged. Writing an undefined position defines it entirely, Unset arms included, whichever mode is given. Writing an already-defined position consults mode for which side decides: StampMode::Above overwrites the base stroke and reads the stamp’s arms, leaving alone whichever ones cell itself leaves Unset; StampMode::Below leaves the base stroke alone and reads the target’s arms instead, writing only the sides the cell already stored has left Unset. A cell holding a literal glyph or a named symbol is decided on every side either way, so it behaves as the fully decided case throughout — see A cell can be a literal instead and A cell can name a symbol instead in docs/model.md. owner is the identity of whoever is stamping, or None for a stamp by nobody: a figure this crate draws on its own gallery carries no identity, and neither does a caller with no diagram to draw from. None records nothing rather than recording an absence — it is not an owner the buffer holds, so a position keeps whoever holds it and answers None where nobody does.

What the stamp records follows the rules that decide the cell rather than sitting beside them, which is what makes the record and the picture one thing instead of two: this stamp owns the position when it decides at least one side of it, and under StampMode::Below only when nobody holds it already. A shape behind therefore cannot take a cell from one in front of it however much it decides there, and since every stamp in front takes, the record comes out the same whichever order a diagram is drawn in.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.