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§
Sourceconst NAME: &'static str
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.
Sourceconst DOC: &'static str
const DOC: &'static str
Doc string. Shown in :describe-buffer when the user
expands a local for detail.
Sourceconst OWNER_MODE: &'static str
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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".