tilo_ui_graph/component.rs
1//! Component descriptions: what each described toolkit widget takes and does, as data.
2//!
3//! A description is generated from the widget's Rust definition (`#[derive(Component)]` in the
4//! toolkit), so it cannot drift from the widget. It is read by everything that composes widgets
5//! without being Rust: tilolang reads the catalogue as its package `ui`, the generic host adapter
6//! builds widgets from it, and a serialized graph names component instances by it.
7//!
8//! A description holds props (typed values), parts (child content, typed by what may go in it),
9//! events (data, never closures), bindings (two-way to a resource field, with the merge an edit is
10//! applied with), state (what the widget keeps between frames, which is lens state) and semantics
11//! (its accessibility role, and which props name it and the resource it shows). [`FORMAT_VERSION`]
12//! is the shape of this format; [`Catalogue::toolkit`] the toolkit version it was generated from.
13
14use serde::{Deserialize, Serialize};
15
16/// The version of the description format: a change to the shape of [`Description`] bumps it.
17pub const FORMAT_VERSION: u32 = 10;
18
19/// The prop a component carries when its block gives such a part: the row offers to open into its
20/// document, which comes once it is open.
21pub const OPENS_PROP: &str = "opens";
22
23/// Every described component of one toolkit version.
24#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
25#[serde(deny_unknown_fields)]
26pub struct Catalogue {
27 /// [`FORMAT_VERSION`] when it was written.
28 pub format: u32,
29 /// The toolkit version the descriptions come from.
30 pub toolkit: String,
31 pub components: Vec<Description>,
32 /// The closed sets with fields a prop can name ([`Type::Cases`]): a drawing's shapes.
33 #[serde(default, skip_serializing_if = "Vec::is_empty")]
34 pub enums: Vec<EnumDescription>,
35 /// The toolkit's icon set, by kebab-case name (`more-horizontal`): what a prop of an icon
36 /// may name, read by tilolang and the tools without linking the toolkit.
37 #[serde(default, skip_serializing_if = "Vec::is_empty")]
38 pub icons: Vec<String>,
39}
40
41/// A closed set whose cases carry fields, as a tilolang `enum` with payloads reads it: the
42/// toolkit declares it once, and every prop of [`Type::Cases`] names it.
43#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
44#[serde(deny_unknown_fields)]
45pub struct EnumDescription {
46 pub name: String,
47 #[serde(default, skip_serializing_if = "String::is_empty")]
48 pub doc: String,
49 pub cases: Vec<CaseDescription>,
50}
51
52/// One case of an [`EnumDescription`], with its fields in order.
53#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
54#[serde(deny_unknown_fields)]
55pub struct CaseDescription {
56 pub name: String,
57 #[serde(default, skip_serializing_if = "String::is_empty")]
58 pub doc: String,
59 #[serde(default, skip_serializing_if = "Vec::is_empty")]
60 pub fields: Vec<FieldDescription>,
61}
62
63/// One field of a [`CaseDescription`].
64#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
65#[serde(deny_unknown_fields)]
66pub struct FieldDescription {
67 pub name: String,
68 pub ty: Type,
69 /// Its value when a case leaves it out; none when it is required.
70 #[serde(default, skip_serializing_if = "Option::is_none")]
71 pub default: Option<Value>,
72 #[serde(default, skip_serializing_if = "String::is_empty")]
73 pub doc: String,
74}
75
76impl Catalogue {
77 /// The description of the component `name`.
78 #[must_use]
79 pub fn get(&self, name: &str) -> Option<&Description> {
80 self.components.iter().find(|c| c.name == name)
81 }
82
83 /// The names of every component, for messages.
84 #[must_use]
85 pub fn names(&self) -> Vec<&str> {
86 self.components.iter().map(|c| c.name.as_str()).collect()
87 }
88
89 /// Read a catalogue written by [`Self::to_json`].
90 ///
91 /// # Errors
92 ///
93 /// The text is not a catalogue, or one of another format version.
94 pub fn from_json(text: &str) -> Result<Self, String> {
95 let catalogue: Self = serde_json::from_str(text).map_err(|e| e.to_string())?;
96 if catalogue.format != FORMAT_VERSION {
97 return Err(format!(
98 "component catalogue format {} is not the supported {FORMAT_VERSION}",
99 catalogue.format
100 ));
101 }
102 Ok(catalogue)
103 }
104
105 /// The catalogue as pretty JSON, one stable text per catalogue.
106 #[must_use]
107 pub fn to_json(&self) -> String {
108 let mut text = serde_json::to_string_pretty(self).unwrap_or_default();
109 text.push('\n');
110 text
111 }
112}
113
114/// The catalogue of the toolkit this crate ships with, as the toolkit generated it
115/// (`components.json`; the toolkit's tests fail while it is stale).
116///
117/// # Panics
118/// Never for the shipped file, which the toolkit's tests read back.
119#[must_use]
120pub fn catalogue() -> &'static Catalogue {
121 static CATALOGUE: std::sync::OnceLock<Catalogue> = std::sync::OnceLock::new();
122 CATALOGUE.get_or_init(|| {
123 #[expect(
124 clippy::expect_used,
125 reason = "the shipped catalogue is written by the toolkit and read back by its tests"
126 )]
127 Catalogue::from_json(SHIPPED).expect("the shipped component catalogue reads")
128 })
129}
130
131/// The text of the shipped catalogue.
132pub const SHIPPED: &str = include_str!("../components.json");
133
134/// One described component.
135#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
136#[serde(deny_unknown_fields)]
137pub struct Description {
138 /// The widget's name, as code calls it (`ListRow`).
139 pub name: String,
140 /// The widget's doc text.
141 pub doc: String,
142 #[serde(default, skip_serializing_if = "Vec::is_empty")]
143 pub props: Vec<Prop>,
144 #[serde(default, skip_serializing_if = "Vec::is_empty")]
145 pub parts: Vec<Part>,
146 #[serde(default, skip_serializing_if = "Vec::is_empty")]
147 pub events: Vec<Event>,
148 #[serde(default, skip_serializing_if = "Vec::is_empty")]
149 pub bindings: Vec<Binding>,
150 #[serde(default, skip_serializing_if = "Vec::is_empty")]
151 pub state: Vec<State>,
152 pub semantics: Semantics,
153}
154
155impl Description {
156 #[must_use]
157 pub fn prop(&self, name: &str) -> Option<&Prop> {
158 self.props.iter().find(|p| p.name == name)
159 }
160
161 #[must_use]
162 pub fn part(&self, name: &str) -> Option<&Part> {
163 self.parts.iter().find(|s| s.name == name)
164 }
165
166 /// The part a component's block fills when it names none.
167 #[must_use]
168 pub fn default_part(&self) -> Option<&Part> {
169 self.parts.iter().find(|s| s.default)
170 }
171
172 #[must_use]
173 pub fn event(&self, name: &str) -> Option<&Event> {
174 self.events.iter().find(|e| e.name == name)
175 }
176
177 #[must_use]
178 pub fn binding(&self, name: &str) -> Option<&Binding> {
179 self.bindings.iter().find(|b| b.name == name)
180 }
181
182 #[must_use]
183 pub fn state(&self, name: &str) -> Option<&State> {
184 self.state.iter().find(|s| s.name == name)
185 }
186
187 /// The props given by position, in order.
188 pub fn positional(&self) -> impl Iterator<Item = &Prop> {
189 self.props.iter().filter(|p| p.positional)
190 }
191
192 /// The first line of the doc text, for messages.
193 #[must_use]
194 pub fn summary(&self) -> &str {
195 first_line(&self.doc)
196 }
197}
198
199/// The first line of a doc text.
200#[must_use]
201pub fn first_line(doc: &str) -> &str {
202 doc.lines().next().unwrap_or("").trim()
203}
204
205/// What a companion says of the prop it completes.
206#[derive(Clone, Copy, Debug, PartialEq, Eq)]
207pub enum Companion {
208 /// `<name>:as`: which kind of text the prop holds (`date`, `time`), for the UI host to
209 /// format it the person's way.
210 Kind,
211 /// `<name>:time`: the instant of the time of day the day the prop holds is due at, which
212 /// reads with the day as one fact (`Today 9:00 AM`).
213 Time,
214}
215
216/// The companion `name` is, and the prop it completes, when it is one: `value:as` says which kind
217/// of text `value` holds, and `meta:time` the time of day the day `meta` is due at.
218///
219/// A companion is the UI host's: it reads it beside the prop it completes, so a component declares
220/// the prop and never the companion. `None` for a name that is no companion.
221#[must_use]
222pub fn companion(name: &str) -> Option<(&str, Companion)> {
223 let (prop, said) = name.rsplit_once(':')?;
224 let companion = match said {
225 "as" => Companion::Kind,
226 "time" => Companion::Time,
227 _ => return None,
228 };
229 Some((prop, companion))
230}
231
232/// A typed value a component takes.
233#[allow(
234 clippy::struct_excessive_bools,
235 reason = "each flag is a separate part of the schema, set by its author"
236)]
237#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
238#[serde(deny_unknown_fields)]
239pub struct Prop {
240 pub name: String,
241 pub doc: String,
242 #[serde(rename = "type")]
243 pub ty: Type,
244 /// Whether every instance gives it.
245 #[serde(default, skip_serializing_if = "is_false")]
246 pub required: bool,
247 /// Whether it may be given by position, in declaration order.
248 #[serde(default, skip_serializing_if = "is_false")]
249 pub positional: bool,
250 /// Whether its text is data the component reads (a key, an address, an emoji) rather than
251 /// words it shows: a view's literal given to it is never a message to translate.
252 #[serde(default, skip_serializing_if = "is_false")]
253 pub data: bool,
254 /// Whether it names the value among its siblings (a list's chosen item, a row's key): a
255 /// filter given to it stands for the query it asks, which the host compares by.
256 #[serde(default, skip_serializing_if = "is_false")]
257 pub identity: bool,
258}
259
260/// Child content a component takes.
261#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
262#[serde(deny_unknown_fields)]
263pub struct Part {
264 pub name: String,
265 pub doc: String,
266 /// What may go in it.
267 pub accepts: Accepts,
268 /// Whether it holds any number of children (else at most one).
269 #[serde(default, skip_serializing_if = "is_false")]
270 pub many: bool,
271 /// Whether it is what the component's block fills when no part is named.
272 #[serde(default, skip_serializing_if = "is_false")]
273 pub default: bool,
274 /// Whether it holds the document a row opens into: rendered only for the open row, so closed
275 /// rows cost none of it. A component with such a part says so (`opens`) where it is built, so a
276 /// row still offers to open.
277 #[serde(default, skip_serializing_if = "is_false")]
278 pub when_open: bool,
279}
280
281/// What a part accepts.
282#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
283#[serde(rename_all = "snake_case")]
284pub enum Accepts {
285 View,
286 /// Only the component of this name, whose props the part's owner reads.
287 Component(String),
288 /// Any of the components of these names, in any order (a menu's commands, separators and
289 /// emoji bar), whose props the part's owner reads.
290 OneOf(Vec<String>),
291}
292
293impl Accepts {
294 /// Whether the part holds components whose props its owner reads, rather than views.
295 #[must_use]
296 pub fn reads_components(&self) -> bool {
297 !matches!(self, Self::View)
298 }
299
300 /// Whether a component of the name `name` may stand in the part.
301 #[must_use]
302 pub fn takes(&self, name: &str) -> bool {
303 match self {
304 Self::View => true,
305 Self::Component(want) => want == name,
306 Self::OneOf(names) => names.iter().any(|want| want == name),
307 }
308 }
309
310 /// What it takes, for messages: `a view`, `` `ui.MenuItem` `` or a list of them.
311 #[must_use]
312 pub fn show(&self) -> String {
313 match self {
314 Self::View => "a view".to_owned(),
315 Self::Component(name) => format!("`ui.{name}`"),
316 Self::OneOf(names) => names
317 .iter()
318 .map(|name| format!("`ui.{name}`"))
319 .collect::<Vec<_>>()
320 .join(", "),
321 }
322 }
323}
324
325/// Something that happens to a component. What it does is data: an action reference, invoked
326/// through the action API, or a view-state update; never a closure.
327#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
328#[serde(deny_unknown_fields)]
329pub struct Event {
330 pub name: String,
331 pub doc: String,
332 /// The value the event carries (the key a list selected), when it carries one.
333 #[serde(default, skip_serializing_if = "Option::is_none")]
334 pub value: Option<Type>,
335 /// Where the value lands, when the event says: a drop's place among the items it was dropped
336 /// on, counted from 0. An event with one carries `[value, at]`.
337 #[serde(default, skip_serializing_if = "Option::is_none")]
338 pub at: Option<Type>,
339 /// Whether the event is the action of the control that raises it: a press runs the action the
340 /// view bound to it, through the action API, so the press and an agent's invocation are the one
341 /// route. An event that is not is the view's own: it is reported to the view.
342 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
343 pub press: bool,
344}
345
346/// A two-way binding to a resource field or view state.
347#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
348#[serde(deny_unknown_fields)]
349pub struct Binding {
350 pub name: String,
351 pub doc: String,
352 #[serde(rename = "type")]
353 pub ty: Type,
354 pub merge: Merge,
355}
356
357/// How an edit through a binding is applied to what it is bound to.
358#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
359#[serde(rename_all = "snake_case")]
360pub enum Merge {
361 /// The value is replaced: a flag, a choice.
362 Register,
363 /// Text: the edit is spliced into it, never written over it, so concurrent edits merge.
364 Splice,
365 /// Rich text: its paragraphs spliced and its marks set, never written over.
366 Rich,
367}
368
369/// What a widget keeps between frames (scroll, selection, caret, expansion). It is lens state:
370/// personal, shown as presence, resumed on the person's other devices.
371#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
372#[serde(deny_unknown_fields)]
373pub struct State {
374 pub name: String,
375 pub doc: String,
376 #[serde(rename = "type")]
377 pub ty: Type,
378}
379
380/// How assistive technology and tests see a component.
381#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
382#[serde(deny_unknown_fields)]
383pub struct Semantics {
384 /// The accessibility role, as `accesskit` names it.
385 pub role: String,
386 /// The prop that names the component to assistive technology, when one does.
387 #[serde(default, skip_serializing_if = "Option::is_none")]
388 pub label: Option<String>,
389 /// The prop holding the resource the component presents, when it presents one.
390 #[serde(default, skip_serializing_if = "Option::is_none")]
391 pub presents: Option<String>,
392 /// The component draws nothing: it gives the view it stands in something to do (a context menu,
393 /// a toolbar on hover, a swipe). Wherever a view's body puts it, it belongs to that view; a
394 /// layout runs the menu a view places in it, and a list item holds its row's.
395 #[serde(default, skip_serializing_if = "is_false")]
396 pub attaches: bool,
397 /// Why the gallery cannot show it (`#[component(not_in_gallery = "…")]` at the component's
398 /// declaration): a component that only means something in a live session, such as a place's
399 /// window well, is left out by its own declaration rather than by a name list in a check.
400 /// `None` when the gallery can show it.
401 #[serde(default, skip_serializing_if = "Option::is_none")]
402 pub not_in_gallery: Option<String>,
403}
404
405/// The type of a prop, an event's value, a binding or a piece of state: the language's types.
406#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
407#[serde(rename_all = "snake_case")]
408pub enum Type {
409 Text,
410 Int,
411 Float,
412 Bool,
413 /// A member: a person or an agent.
414 Actor,
415 /// A resource the component presents.
416 Resource,
417 /// A moment: a date and a time of day, as the language's `Time`.
418 Time,
419 /// One of the platform's icons, by its kebab-case name.
420 Icon,
421 /// A picture: where its bytes are read from, and what it shows the person.
422 Picture,
423 /// A file a person handed the window — dropped on it, or chosen — as the runtime's `File`:
424 /// what it is called, its media type, its size and where its bytes are.
425 File,
426 /// Rich text, with how its references read for the person reading it.
427 RichText,
428 /// One of a closed set of cases: the design system's roles and tokens.
429 Choice {
430 name: String,
431 cases: Vec<String>,
432 },
433 Option(Box<Type>),
434 List(Box<Type>),
435 /// Distinct values in no order the component relies on: who reacted with an emoji.
436 Set(Box<Type>),
437 /// Values by key: the people who reacted, by emoji.
438 Map {
439 key: Box<Type>,
440 value: Box<Type>,
441 },
442 /// An action offered to the person, as a control shows it: what it is called, its icon and
443 /// role, and what choosing it runs (an event of the instance, never a closure).
444 Action,
445 /// One case of the catalogue's closed set `name` whose cases carry fields: a drawing's shape.
446 Cases {
447 name: String,
448 },
449 /// A case of one of the app's own enums, by its name: which cases it holds is the field the
450 /// binding names, so a description says only that it takes such a field.
451 Enum,
452 /// A record a view names, as the component offers it: what refers to it, and how it reads for
453 /// the person now. What the component writes names the record, never the text, so a record
454 /// renamed later reads by its new title everywhere it was linked.
455 Link,
456}
457
458impl Type {
459 /// How the type reads in messages: `Option<Text>`, `TextRole`.
460 #[must_use]
461 pub fn show(&self) -> String {
462 match self {
463 Self::Text => "Text".into(),
464 Self::Int => "Int".into(),
465 Self::Float => "Float".into(),
466 Self::Bool => "Bool".into(),
467 Self::Actor => "Actor".into(),
468 Self::Resource => "a resource".into(),
469 Self::Time => "Time".into(),
470 Self::Icon => "Icon".into(),
471 Self::Picture => "Picture".into(),
472 Self::File => "File".into(),
473 Self::RichText => "RichText".into(),
474 Self::Choice { name, .. } | Self::Cases { name } => name.clone(),
475 Self::Option(inner) => format!("Option<{}>", inner.show()),
476 Self::List(inner) => format!("List<{}>", inner.show()),
477 Self::Set(inner) => format!("Set<{}>", inner.show()),
478 Self::Map { key, value } => format!("Map<{}, {}>", key.show(), value.show()),
479 Self::Action => "Action".into(),
480 Self::Enum => "a case of an enum".into(),
481 Self::Link => "Link".into(),
482 }
483 }
484}
485
486/// A value of a [`Type`], as an instance of a component holds it.
487#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
488#[serde(rename_all = "snake_case")]
489pub enum Value {
490 Text(String),
491 Int(i64),
492 Float(f64),
493 Bool(bool),
494 /// Who acted, what the workspace calls them, and the presence palette slot it paints them
495 /// in (`None`: derived from `identity`).
496 Actor {
497 identity: tilo_action_policy::Actor,
498 name: String,
499 #[serde(default)]
500 hue: Option<u8>,
501 /// The address of their picture (a `data:` or `tilo-blob://` URL), when the workspace
502 /// shows one; `None` shows their initials.
503 #[serde(default)]
504 picture: Option<String>,
505 },
506 /// A resource, by its id.
507 Resource(String),
508 /// An icon's kebab-case name.
509 Icon(String),
510 /// A picture: its address (where a host reads its bytes) and what it says to assistive
511 /// technology.
512 Picture(Picture),
513 /// A file a person handed the window: its name, its media type, how many bytes it is and
514 /// where they are (`tilo-blob://<hash>`), as the runtime's `File` value holds it.
515 File(File),
516 /// A case of a choice, by name.
517 Choice(String),
518 /// Rich text, with how its references read for the person reading it.
519 Rich(crate::rich::RichText),
520 /// An `Option` that holds nothing.
521 None,
522 /// A list, or a set's values in the order they were given.
523 List(Vec<Value>),
524 /// A map's entries, each key once, in key order.
525 Map(Vec<(Value, Value)>),
526 /// An action offered to the person.
527 Action(Offered),
528 /// A case of a [`Type::Cases`] set, with its fields' values in the case's order.
529 Case {
530 case: String,
531 fields: Vec<(String, Value)>,
532 },
533 /// A record a view names: what refers to it (the catalogue's reference, `tilo_reference`),
534 /// and how it reads for the person now (its title, or the phrase for one they cannot read).
535 Link {
536 reference: String,
537 title: String,
538 },
539}
540
541/// A picture a component shows, by where its bytes are. The address is opaque to the toolkit: a
542/// window whose host holds a content store reads `tilo-blob://<hash>`, and any other address is
543/// fetched by the store the picture loads through.
544#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
545#[serde(deny_unknown_fields)]
546pub struct Picture {
547 /// Where its bytes are read from: a content address (`tilo-blob://<hash>`) or a URL.
548 pub src: String,
549}
550
551/// A file a person handed the window: dropped on it, or chosen in a chooser. Its bytes are in the
552/// device's content store, and the value is what the runtime's `File` reads: its name, its media
553/// type, its size and the content address its bytes are at.
554#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
555#[serde(deny_unknown_fields)]
556pub struct File {
557 /// What the person's file is called, extension included (`Q3 plan.md`).
558 pub name: String,
559 /// Its media type (`text/markdown`).
560 pub media: String,
561 /// How many bytes its content is.
562 pub size: i64,
563 /// Where its bytes are: a content address (`tilo-blob://<hash>`).
564 pub url: String,
565}
566
567/// An action offered to the person, as a control shows it, and the event of the instance that
568/// choosing it fires. Every field is always written: the wire's encoding is not self-describing.
569#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
570#[serde(deny_unknown_fields)]
571pub struct Offered {
572 /// What it does, as a button or a menu names it.
573 pub label: String,
574 /// Its icon's kebab-case name, when it has one.
575 pub icon: Option<String>,
576 /// Whether it is its resource's primary action.
577 pub primary: bool,
578 /// Whether it takes something away: undone, not confirmed.
579 pub destructive: bool,
580 /// Whether the state it toggles is on, when it toggles one.
581 pub on: Option<bool>,
582 /// `key: "e"`: the plain key that runs it while its window has the keyboard (and, on a row's
583 /// action, while that row is selected). `None` when it declares none.
584 pub key: Option<String>,
585 /// The event of the instance choosing it fires.
586 pub event: String,
587}
588
589impl Value {
590 /// The type the value is of, as far as the value says (`None` and an empty list say nothing).
591 #[must_use]
592 pub fn kind(&self) -> &'static str {
593 match self {
594 Self::Text(_) => "Text",
595 Self::Int(_) => "Int",
596 Self::Float(_) => "Float",
597 Self::Bool(_) => "Bool",
598 Self::Actor { .. } => "Actor",
599 Self::Resource(_) => "a resource",
600 Self::Icon(_) => "Icon",
601 Self::Picture(_) => "a picture",
602 Self::File(_) => "a file",
603 Self::Choice(_) | Self::Case { .. } => "a case",
604 Self::Rich(_) => "RichText",
605 Self::None => "nothing",
606 Self::List(_) => "List",
607 Self::Map(_) => "Map",
608 Self::Action(_) => "Action",
609 Self::Link { .. } => "Link",
610 }
611 }
612}
613
614#[expect(
615 clippy::trivially_copy_pass_by_ref,
616 reason = "serde's skip_serializing_if passes a reference"
617)]
618fn is_false(flag: &bool) -> bool {
619 !*flag
620}
621
622#[cfg(test)]
623mod tests {
624 use super::*;
625
626 #[test]
627 fn the_shipped_catalogue_reads_and_names_each_component_once() {
628 let catalogue = catalogue();
629 let mut names = catalogue.names();
630 let all = names.len();
631 names.sort_unstable();
632 names.dedup();
633 assert_eq!(names.len(), all, "a component is described once");
634 assert!(catalogue.get("ListRow").is_some());
635 }
636
637 #[test]
638 fn a_catalogue_of_another_format_is_refused() {
639 // A catalogue otherwise as this build writes it, numbered as another format's.
640 let mut other = catalogue().clone();
641 other.format = FORMAT_VERSION + 1;
642 let text = serde_json::to_string(&other).unwrap_or_default();
643 assert!(Catalogue::from_json(&text).is_err());
644 }
645}