Skip to main content

RuleReference

Enum RuleReference 

Source
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

Source

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

Source§

fn clone(&self) -> RuleReference

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 RuleReference

Source§

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

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

impl Eq for RuleReference

Source§

impl PartialEq for RuleReference

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RuleReference

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

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

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

Source§

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

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ParallelSend for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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.