Skip to main content

Crate yog_data

Crate yog_data 

Source
Expand description

Yog Data: one data model, text syntax, binary form and schema system for every Yog format, the build, the ABI and the IDE — the way Minecraft has NBT. See docs/design/yog-data.md.

  • Value: the model — JSON’s values plus typed ones (content references, tags, mod resources, Yog text, images, colors);
  • text: JSON with comments, trailing commas and unquoted keys, parsed with the position of every value;
  • typed: the one grammar of the typed values’ string forms (@item:minecraft:stick, @tag:item:minecraft:planks, @Strings.title);
  • binary: the compact tagged form content crosses the ABI in.

Re-exports§

pub use atom::Atom;
pub use text::Doc;
pub use text::LineCol;
pub use text::Span;
pub use text::Spans;
pub use text::SyntaxError;
pub use schema::AnyRefOrTag;
pub use schema::BlockId;
pub use schema::Color;
pub use schema::EntityId;
pub use schema::Errors;
pub use schema::Id;
pub use schema::Image;
pub use schema::ItemId;
pub use schema::ItemIdOrTag;
pub use schema::Kind;
pub use schema::Kinds;
pub use schema::OneOrList;
pub use schema::OneOrTag;
pub use schema::Ordered;
pub use schema::Read;
pub use schema::Reader;
pub use schema::RecipeId;
pub use schema::Resolve;
pub use schema::Schema;
pub use schema::Shape;
pub use schema::TagId;
pub use schema::Text;
pub use schema::built_in;
pub use schema::from_doc_with;
pub use schema::from_text;
pub use schema::from_value;
pub use schema::from_value_with;
pub use schema::kinds;
pub use schema::read_bytes;
pub use schema::read_ref_value;
pub use schema::read_value;
pub use schema::to_bytes;
pub use schema::to_text;

Modules§

atom
Atoms: names that repeat across messages (minecraft:stone, a live entity’s kind) kept once a process and sent on the bus as their number. An Atom is a u32: copied, compared and packed as one; its text is the table’s, alive as long as the process. A frame carries the number, every other form (text, the tagged binary form, files) the text — the numbers mean nothing outside the process.
binary
The binary form — what the build compiles content to, what the bus carries, and what the runtime and the Java hosts read, like NBT:
export
The binary form’s constants for the other languages’ readers — the IDE’s TypeScript (yog-data-export), so the tags are written once.
frame
Frames: Yog Data packed for the bus — both sides know the schema, so nothing says what a value is or what it’s called. A record’s fields go in the order they’re declared, after the record’s length (so a reader that knows fewer fields skips the rest; one that knows more takes their defaults: fields are only ever appended). Strings go in a table at the end, each once; the body refers to them by index.
io
Yog Data over a byte stream — a socket, a pipe: each message a frame, its length (a little-endian u32) and then its binary form. What Yog’s programs say to each other (the game’s control channel, yog serve).
patch
Editing Yog Data text in place: patch changes a document to hold a new value and keeps everything that didn’t change as it was — comments, key order, number spelling, layout. What changed is written by [format], the way Yog’s editors write a value.
schema
Schemas: a format is a Rust type implementing Schema (usually #[derive(Schema)]). One schema reads and writes the format, checks it with the path of every problem, collects its references for the build to check, and describes itself (Shape) for Yog-IDLE’s editors and the docs.
source
A source file as it’s kept and as it’s read: on disk binary Yog Data (what the editor saves), to people its text — formatted as Yog’s editors write it, so a line in an error is the line the editor shows. A file still in text is read as it is.
text
The text syntax: JSON, plus // and /* */ comments, trailing commas and unquoted keys (the part of JSON5 editors already understand).
typed
The typed values’ string forms — one grammar for every format:
with
Field codecs: #[data(with = "…")] reads and writes a field through a type other than its own — like serde’s with. The field keeps the plain type a program uses (String), the format says what it holds (an item reference, a text), checked and resolved by the Reader’s Resolve.

Macros§

field
Field ident of struct T as files write it: field!(BlockProps, tool_level) → "tool_level". A field T hasn’t got doesn’t compile.
kind
Declares kinds of content: yog_data::kind!(Pattern = "pattern");.

Structs§

Bump
An arena to bump allocate into.
Map
A map: entries in file order, keys unique. Keys are shared: a decoded document allocates each distinct key once, however many maps have it.
MapRef
A borrowed map: entries in file order.
Path
Where a value is in a document: entries[2].pages[0].item.
Ref
A reference to content: its kind (item, block, entity, recipe, entry, category, or a mod’s own) and id (minecraft:stick, minecraft:furnace[facing=north]).
Res
A mod resource: @<set>.<key> — @Strings.screen.title is set Strings, key screen.title.
Stream
A list of T kept written: its body in the binary form, its strings its own.
StreamWriter
Writes a Stream’s items as they come.

Enums§

Seg
One step of a Path.
Value
A Yog Data value.
ValueRef
A borrowed Value: the same cases, strings &'a str, lists and maps slices.

Derive Macros§

Schema