Skip to main content

BufferLocal

Trait BufferLocal 

Source
pub trait BufferLocal:
    Any
    + Clone
    + Send
    + Sync
    + 'static {
    const NAME: &'static str;
    const DOC: &'static str;
    const OWNER_MODE: &'static str;

    // Required method
    fn describe(&self) -> String;
}
Expand description

Compile-time declaration of a mode-owned per-buffer local.

Implementing types are typically newtypes wrapping the underlying data:

use lattice_mode::{BufferLocal, BufferLocals};

#[derive(Clone)]
pub struct FileTreeEntries(pub Vec<String>);

impl BufferLocal for FileTreeEntries {
    const NAME: &'static str = "file-tree.entries";
    const DOC: &'static str = "Tree-of-files entries for this buffer.";
    const OWNER_MODE: &'static str = "file-tree-mode";
    fn describe(&self) -> String {
        format!("{} entries", self.0.len())
    }
}

let mut locals = BufferLocals::new();
locals.insert(FileTreeEntries(vec!["src/".into(), "Cargo.toml".into()]));
assert_eq!(locals.get::<FileTreeEntries>().unwrap().0.len(), 2);

// `:describe-buffer` sees it without knowing the concrete type.
let d = locals.iter_descriptors().next().unwrap();
assert_eq!((d.name, d.owner_mode, d.describe.as_str()), ("file-tree.entries", "file-tree-mode", "2 entries"));

'static bound: locals key on TypeId, which requires the type to be 'static. Send + Sync so a buffer can be shared across threads. Slice 3c.final.B.9: Clone is required so the typed-map can be deep-cloned for the BufferLocalsRenderState per-publish snapshot. Every existing impl is already a wrapper around Clone primitives (Vec<T> / PathBuf / scalars), so the bound adds no real constraint — just lets LocalDyn::clone_box work through the dyn trait object.

Required Associated Constants§

Source

const NAME: &'static str

Public display name (:describe-buffer row label, debug logs). Convention: <owner-mode-name>.<key>, e.g. "file-tree.entries". Not a registry key — locals aren’t registered globally; the name is metadata for inspection.

Source

const DOC: &'static str

Doc string. Shown in :describe-buffer when the user expands a local for detail.

Source

const OWNER_MODE: &'static str

Mode id that owns this local. Attribution metadata for :describe-buffer; the write-time check the design calls for (a ModeContext::set_local::<T> that rejects a non-owner) is not implemented, so nothing enforces it today (see the module docs).

Required Methods§

Source

fn describe(&self) -> String

Single-line summary of the local’s value for :describe-buffer’s tabular display. Implementations should be cheap (no heavy formatting); detailed inspection is via the mode’s own commands.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl BufferLocal for ActiveCompletionSources

Source§

const NAME: &'static str = "completion-mode.active-sources"

Source§

const DOC: &'static str = "Cached active insert-completion source set for this \ buffer. Recomputed on every mode-activation / \ -deactivation transition; read by the aggregator on \ the popup-open / refilter path."

Source§

const OWNER_MODE: &'static str = "completion-mode"

Source§

impl BufferLocal for BufferScopeDir

Source§

const NAME: &'static str = "text-mode.scope-dir"

Source§

const DOC: &'static str = "The directory this buffer is about, for a buffer that is not \ itself a file — a magit repository, an oil listing's directory, a \ file tree's root, a search or agenda view's scan root. Project \ resolution (`:files`, `:search`) reads it before falling back to \ the buffer's own path, and then to the working directory."

Source§

const OWNER_MODE: &'static str = "text-mode"