Skip to main content

Module ids

Module ids 

Source
Expand description

Newtype identifiers for editor entities.

Every id is a u64 newtype, so it fits one register, round-trips through a WIT u64 without precision loss, and serializes as the bare number (#[serde(transparent)]). The point of the newtypes is nominal: a DocumentId and a BufferId with the same raw value are different types and cannot be compared or passed for one another by accident.

This module only defines the types; it issues nothing. Each id is minted by the subsystem that owns the entity, which decides uniqueness and lifetime (documented per type below). The convention those minters follow: monotonically increasing values, never reused within a process. 0 is the Default and is conventionally “none / not yet assigned”.

Several ids are declared ahead of their consumers: the pane, tab, window and plugin subsystems currently mint their own narrower ids (in lattice-core and lattice-plugin-host), and the ids here are the planned wire-level spelling. Each type’s doc says which case it is.

§Examples

use lattice_protocol::{BufferId, DocumentId};

let doc = DocumentId::new(42);
assert_eq!(doc.raw(), 42);
assert_eq!(DocumentId::new(doc.raw()), doc); // lossless round-trip
assert_eq!(doc.to_string(), "DocumentId#42"); // Display names the type

// Ids order by their raw value, and serialize as the bare number.
assert!(BufferId::new(1) < BufferId::new(2));
assert_eq!(serde_json::to_string(&BufferId::new(7)).unwrap(), "7");

Structs§

BufferId
Identifies one entry of the host’s buffer registry (a document, file tree, help view, multibuffer, terminal, …) at the protocol level.
CommandId
Identifies a registered command — the command of a lattice_grammar::CommandInvocation, and what a keymap binding resolves to. Minted at registration by lattice-grammar’s command registry from a process-wide counter starting at 1. (The completion registry keeps a separate counter of its own, so an id is only meaningful together with the registry that issued it.)
DocumentId
Identifies one lattice_core::Document — a text buffer with its undo history, selections and path — for its whole lifetime.
MajorModeId
Identifies a major mode. Declared for the protocol; modes are currently identified by lattice_mode::ModeId, and events carry the mode’s canonical name as a String.
MinorModeId
Identifies a minor mode. Declared for the protocol; see MajorModeId for how modes are identified today.
PaneId
Identifies a pane (a split showing one buffer). Declared for the protocol; the layout currently mints its own lattice_core::ui::PaneId(u32).
PluginId
Identifies a loaded plugin instance. Declared for the protocol; the plugin host currently mints its own lattice_plugin_host::PluginId, and plugin events carry it as a bare u32 (Event::PluginCrashed).
TabId
Identifies a tab page. Declared for the protocol; the tab subsystem currently mints its own lattice_core::ui::TabId(u32).
WindowId
Identifies an OS-level editor window. Declared for the protocol; no subsystem mints it yet (the editor runs one window).