Skip to main content

RuleSource

Enum RuleSource 

Source
pub enum RuleSource {
    Baked {
        text: &'static str,
    },
    Disk {
        path: PathBuf,
    },
}
Expand description

A source of rule text yielding a runtime Ruleset, in one of two modes (doc 11 §4.2). Both modes call the same Ruleset::from_ron, so a baked build and a disk build of the same rules.ron produce byte-identical rulesets — the dual-mode guarantee.

Variants§

§

Baked

Baked (RELEASE): the canonical rules.ron text compiled into the binary via the caller’s include_str!. Zero file IO. The default build.

Fields

§text: &'static str

The include_str!’d source text.

§

Disk

Disk (DEV): rules.ron read from a file path. With the hot-reload feature a Watcher observes the file and poll_changed signals edits so the registry is rebuilt between turns.

Fields

§path: PathBuf

The on-disk rules.ron path.

Implementations§

Source§

impl RuleSource

Source

pub fn baked(text: &'static str) -> Self

A baked source over include_str!’d text (RELEASE; the default build). The text is compiled into the binary; loading never touches the filesystem.

Source

pub fn from_path(path: impl Into<PathBuf>) -> Self

A disk source over a rules.ron path (DEV). Without the hot-reload feature this still reads the file at load time (it just never watches it); with the feature it also starts a watcher so poll_changed can signal edits.

Source

pub fn load(&self) -> Result<Ruleset, LoadError>

Read the current rule text + parse it into a Ruleset. The decisive dual-mode invariant: baked text and disk text run through the same Ruleset::from_ron, so identical bytes ⇒ identical ruleset.

Source

pub fn poll_changed(&mut self) -> bool

Poll whether the on-disk rules.ron has changed since the last poll (DEV / hot-reload). A true return is the game’s cue to re-load and rebuild the compiled registry between turns (safe mid-battle — doc 11 §4.2). A baked source never changes ⇒ always false; a disk source without the hot-reload feature also returns false (no watcher).

Source

pub fn is_hot_reloadable(&self) -> bool

Whether this source can hot-reload (a disk source with a live watcher). false for a baked source or a feature-off build. Useful for diagnostics.

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