Skip to main content

yog_formats/rules/
mod.rs

1//! What a file must keep that its schema alone doesn't say — fields that
2//! don't go together, a size that can't be zero — read off the file alone,
3//! no other file or the project needed. [`crate::problems`] adds them to the
4//! schema's, so an editor shows them as the file is edited; the build reads
5//! the same.
6
7mod block;
8mod element;
9mod item;
10mod kind;
11mod model;
12mod recipe;
13mod states;
14
15use yog_data::{Atom, Diagnostic, Path};
16
17/// The rules a format's file keeps beyond its schema.
18pub trait Rules {
19    /// Every rule it breaks, into `out`.
20    fn rules(&self, _out: &mut Vec<Diagnostic>) {}
21}
22
23/// A broken rule at `path`.
24fn error(path: Path, message: impl std::fmt::Display) -> Diagnostic {
25    Diagnostic::error(Atom::new(yog_ids::build_problem::CONTENT), message).at_path(path)
26}
27
28/// Something that won't do what it says, at `path`.
29fn warning(path: Path, message: impl std::fmt::Display) -> Diagnostic {
30    Diagnostic::warning(Atom::new(yog_ids::build_problem::CONTENT), message).at_path(path)
31}
32
33/// The formats whose files keep no rules beyond their schema.
34macro_rules! no_rules {
35    ($($t:ty),* $(,)?) => {$( impl Rules for $t {} )*};
36}
37
38no_rules!(
39    yog_registry::EntityDef,
40    crate::sound::SoundFile,
41    yog_registry::Particle,
42    crate::video::Video,
43    crate::book::Book,
44    crate::def::Def,
45    crate::yres::YresFile,
46    yog_body::format::ModelFile,
47    yog_body::format::AnimFile,
48    yog_font::Font,
49    crate::texture::TextureFile,
50    crate::material::MaterialFile,
51);
52
53#[cfg(test)]
54mod tests;