substrate_data/names.rs
1//! The words the formats share, defined once: the typed value grammar's
2//! mark and the keys a format's own structure uses. Problem codes are
3//! [`crate::diagnostic::Problem`]; the words a shape is described by are
4//! [`crate::schema::ShapeNode`]'s variants.
5
6use std::fmt;
7
8/// What starts a typed value: `@file:images/logo.png`.
9pub const TYPED: char = '@';
10
11/// Keys a format's own structure uses.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum Word {
14 /// The key naming a tagged enum's variant: `{ type: "estimate", … }`.
15 Type,
16 /// Where a tagged enum's variant keeps what it wraps when that isn't a struct.
17 Value,
18}
19
20impl Word {
21 /// As written.
22 #[must_use]
23 pub const fn as_str(self) -> &'static str {
24 match self {
25 Word::Type => "type",
26 Word::Value => "value",
27 }
28 }
29}
30
31impl fmt::Display for Word {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 f.write_str(self.as_str())
34 }
35}