Skip to main content

setzer_model/
lib.rs

1//! Semantic document model for Kernsetzer.
2//!
3//! A `Book` describes *what* a manuscript contains (chapters, paragraphs,
4//! emphasis, scene breaks, front and back matter), never *how* it is laid
5//! out. Layout decisions live in `StyleSettings` (theme + parameters) and in
6//! the themes themselves.
7//!
8//! This crate must not depend on any other setzer crate.
9
10pub mod asset;
11pub mod book;
12pub mod isbn;
13pub mod presets;
14pub mod project;
15pub mod table;
16pub mod text;
17
18pub use asset::Asset;
19pub use book::*;
20pub use project::{Meta, Project, ProjectError};
21pub use table::{ColumnAlign, PlacedCell, Table, TableCell, TableColumn, TableLayout};
22
23/// Version of the `book.json` schema (and `.kernsetzer` container) written by
24/// this build. Bump when a change is not backwards compatible, append a
25/// step to `project::MIGRATIONS` and commit a fixture of the old version.
26pub const FORMAT_VERSION: u32 = 2;
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31    use serde::Serialize;
32    use serde::de::DeserializeOwned;
33    use std::fmt::Debug;
34
35    /// Model types are plain data: JSON in `book.json` and over the app's
36    /// IPC, comparable in tests. Not `Asset` and `Project`: they hold image
37    /// bytes, travel only inside the `.kernsetzer` archive, and asset metadata
38    /// is derived from the bytes.
39    #[test]
40    fn model_types_are_plain_data() {
41        fn plain<T: Serialize + DeserializeOwned + Clone + PartialEq + Debug>() {}
42        plain::<Book>();
43        plain::<Lang>();
44        plain::<Metadata>();
45        plain::<Series>();
46        plain::<Imprint>();
47        plain::<Credit>();
48        plain::<SectionKind>();
49        plain::<Section>();
50        plain::<Numbering>();
51        plain::<Epigraph>();
52        plain::<Block>();
53        plain::<Inline>();
54        plain::<Table>();
55        plain::<TableColumn>();
56        plain::<TableCell>();
57        plain::<ColumnAlign>();
58        plain::<StyleSettings>();
59        plain::<BlockRef>();
60        plain::<presets::TrimSize>();
61        plain::<presets::Retailer>();
62        plain::<presets::MinMargins>();
63        plain::<Meta>();
64    }
65}