pub enum RuleReference {
Builtin(String),
BuiltinComponent(String),
Component(PathBuf),
Module(String),
}Expand description
What a rule reference in a lanekeep.json names.
Deciding this in Rust is the whole of the un-coupling: a reference used to become an
import statement whose meaning only the module loader knew, and is now a value the
rest of the crate can read without evaluating anything.
Variants§
Builtin(String)
A rule shipped with lanekeep, authored in TypeScript. Carries the name after the
prefix, so "lanekeep/no-package-init" is Builtin("no-package-init").
Which bytes that name resolves to is the loader’s business; the name is what a config wrote, and it is decided here.
BuiltinComponent(String)
A rule shipped with lanekeep, compiled to a component.
The distinction is not one a config writes. Both spellings are lanekeep/<name>,
and which of the two a name is depends only on how that rule happens to be authored in
the build the user is running. A rule migrating from TypeScript to Rust must not require
anybody to edit their config, which is the whole point of resolving the prefix here
rather than making the format carry the answer.
Its own variant rather than a RuleReference::Component holding a synthetic path,
because a built-in has no path: its bytes are embedded in the binary, so there is
nothing to confine, nothing to read and nothing a project file could shadow.
Component(PathBuf)
A compiled rule component on disk, as in "./rules/no-package-init.wasm".
The path is the reference resolved against the rules root — the same anchor a relative module specifier resolves against, since the synthetic entry module sits there.
Resolved rather than merely recognized: crate::describe_components loads these bytes
at config load and asks the component what it is, because a .wasm carries its own
id, query, card and gates and there is no config syntax for any of them.
Module(String)
A rule module on disk, as in "./lanekeep/rules/mine.ts".
Carries the specifier as written rather than a path, because the extension is
optional — ./rule finds rule.ts — and reproducing the loader’s search here would
be a second implementation of it.
Implementations§
Source§impl RuleReference
impl RuleReference
Sourcepub const fn is_component(&self) -> bool
pub const fn is_component(&self) -> bool
Whether this reference’s handlers live in a component rather than in JavaScript.
One question asked in three places — the entry module’s placeholder, the early return in
crate::describe_components, and the description loop — so that adding a third way for a
component to be named cannot leave one of them behind. A matches! at each site is what
let BuiltinComponent be added and forgotten, and every symptom of forgetting is silent:
a placeholder not emitted shifts every later rule’s handler by one, and a reference not
described becomes a rule with no check.
Trait Implementations§
Source§impl Clone for RuleReference
impl Clone for RuleReference
Source§fn clone(&self) -> RuleReference
fn clone(&self) -> RuleReference
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 RuleReference
impl Debug for RuleReference
impl Eq for RuleReference
Source§impl PartialEq for RuleReference
impl PartialEq for RuleReference
impl StructuralPartialEq for RuleReference
Auto Trait Implementations§
impl Freeze for RuleReference
impl RefUnwindSafe for RuleReference
impl Send for RuleReference
impl Sync for RuleReference
impl Unpin for RuleReference
impl UnsafeUnpin for RuleReference
impl UnwindSafe for RuleReference
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more