pub struct SourceLocation {
pub layer: SourceLayer,
pub kind: SourceKind,
}Expand description
Where a registered command, binding or option came from: who put it
there (SourceLayer) and where to look (SourceKind).
§Examples
use lattice_grammar::{SourceLayer, SourceLocation};
let src = SourceLocation::builtin_file("crates/lattice-grammar/src/builtins.rs", 42);
assert_eq!(src.layer, SourceLayer::Builtin);
assert_eq!(
src.as_link(),
"[crates/lattice-grammar/src/builtins.rs:42](file:crates/lattice-grammar/src/builtins.rs:42)",
);
// A plugin source renders its manifest name when the caller can resolve it.
let p = SourceLocation::plugin(3);
assert_eq!(p.as_link(), "[<plugin:3>](synthetic:plugin:3)");
assert_eq!(
p.as_link_with(&|id| (id == 3).then(|| "comment".to_string())),
"[plugin:comment](synthetic:plugin:comment)",
);Fields§
§layer: SourceLayerWho contributed the item; rendered as SourceLayer::label.
kind: SourceKindWhere the link follower should go.
Implementations§
Source§impl SourceLocation
impl SourceLocation
Sourcepub fn builtin_file(file: &str, line: u32) -> Self
pub fn builtin_file(file: &str, line: u32) -> Self
Construct a Builtin source from a (file, line) pair.
Almost always called via Location::caller() in a
#[track_caller] registration method.
Sourcepub fn synthetic(tag: impl Into<String>) -> Self
pub fn synthetic(tag: impl Into<String>) -> Self
Synthetic source for tests + the rare runtime case where no concrete origin exists.
Sourcepub fn plugin_named(plugin_id: u32, name: &str) -> Self
pub fn plugin_named(plugin_id: u32, name: &str) -> Self
Self::plugin, with the plugin’s manifest name – which is what a
reader wants. plugin:comment answers “where did gc come from”;
plugin:1 makes them go and look the number up.
Separate from Self::plugin because the name is not always in hand:
register_plugin_* runs in the drain with only an id, while a caller
that holds the manifest can do better.
Sourcepub fn plugin(plugin_id: u32) -> Self
pub fn plugin(plugin_id: u32) -> Self
Provenance for a WASM-plugin contribution (Phase 7). The layer is
SourceLayer::Plugin carrying the host-issued plugin_id (§6 —
the guest never supplies it, so a plugin cannot forge a builtin/user
provenance); the kind is a synthetic plugin:N tag (a plugin has no
file/line the link follower could open — the plugin-manager view is the
eventual target). This is the only forgery-safe way a cross-crate
trusted subsystem stamps Plugin provenance: the public
CommandRegistry::register_plugin_* methods take a u32, never a
SourceLocation, and route through here.
Display sites that can resolve the id to a manifest name do so through
Self::as_link_with; prefer Self::plugin_named when the name is
already known.
Sourcepub fn as_link(&self) -> String
pub fn as_link(&self) -> String
Render as a markdown link for inclusion in a help body.
Format: [label](scheme:value). The link’s URL portion is
what parse_help_links (in lattice-ui-tui::help)
classifies into a typed lattice_ui_tui::help::HelpLinkTarget; the label
is what the user sees.
Sourcepub fn as_link_with(
&self,
resolve_plugin: &dyn Fn(u32) -> Option<String>,
) -> String
pub fn as_link_with( &self, resolve_plugin: &dyn Fn(u32) -> Option<String>, ) -> String
Self::as_link, with a way to name a plugin.
The LAYER is authoritative about a source being a plugin’s — the
kind is only a tag, and one stamped by whichever registration path
happened to run. So the resolver is consulted on SourceLayer::Plugin
and its answer wins, which means every display site gets the manifest
name regardless of what was stamped, and plugin:1 survives only where
the plugin genuinely cannot be named (unloaded, or a harness with no
meta registry).
Trait Implementations§
Source§impl Clone for SourceLocation
impl Clone for SourceLocation
Source§fn clone(&self) -> SourceLocation
fn clone(&self) -> SourceLocation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SourceLocation
impl Debug for SourceLocation
Source§impl<'de> Deserialize<'de> for SourceLocation
impl<'de> Deserialize<'de> for SourceLocation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for SourceLocation
Source§impl PartialEq for SourceLocation
impl PartialEq for SourceLocation
Source§impl Serialize for SourceLocation
impl Serialize for SourceLocation
impl StructuralPartialEq for SourceLocation
Auto Trait Implementations§
impl Freeze for SourceLocation
impl RefUnwindSafe for SourceLocation
impl Send for SourceLocation
impl Sync for SourceLocation
impl Unpin for SourceLocation
impl UnsafeUnpin for SourceLocation
impl UnwindSafe for SourceLocation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.