Skip to main content

SourceLocation

Struct SourceLocation 

Source
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: SourceLayer

Who contributed the item; rendered as SourceLayer::label.

§kind: SourceKind

Where the link follower should go.

Implementations§

Source§

impl SourceLocation

Source

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.

Source

pub fn synthetic(tag: impl Into<String>) -> Self

Synthetic source for tests + the rare runtime case where no concrete origin exists.

Source

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.

Source

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.

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.

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

Source§

fn clone(&self) -> SourceLocation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceLocation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SourceLocation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for SourceLocation

Source§

impl PartialEq for SourceLocation

Source§

fn eq(&self, other: &SourceLocation) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SourceLocation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SourceLocation

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more