yog_data/built_in/mod.rs
1//! Tables a crate ships, read as they're needed.
2
3use substrate_data::{Schema, from_text};
4
5/// A table a crate ships (`include_str!` of its `.ydata`), read: what it
6/// says, or — when it won't read, which its crate's tests catch — the
7/// error logged (`what`: which table) and its default.
8pub fn built_in<T: Schema + Default>(what: &str, text: &str) -> T {
9 match from_text::<T>(text) {
10 Ok(read) => read.value,
11 Err(e) => {
12 yog_logging::error!("{what} won't read: {e}");
13 T::default()
14 }
15 }
16}