switchback_traits/traits/entity_category.rs
1//! `EntityCategory` marker trait and renderer-known generic categories.
2
3use std::fmt::Debug;
4use std::hash::Hash;
5
6/// Typed entity category owned by each contract family.
7///
8/// Family parsers define a concrete enum or newtype implementing this trait.
9/// Renderers use [`EntityCategory::to_generic`] to apply cross-family formatting
10/// rules via [`GenericCategory`].
11pub trait EntityCategory:
12 Copy + Clone + Eq + PartialEq + Hash + Debug + Send + Sync + 'static
13{
14 /// Wire-safe category slug (e.g. `"schemas"`, `"operations"`).
15 fn as_str(&self) -> &'static str;
16
17 /// Output directory segment for entities of this category.
18 fn dir(&self) -> &str;
19
20 /// Prefix used when generating SUMMARY entries for this category.
21 fn summary_prefix(&self) -> &str;
22
23 /// Maps this family-specific category to a renderer-known generic bucket, if any.
24 fn to_generic(&self) -> Option<GenericCategory>;
25}
26
27/// Categories renderers know how to format specially.
28///
29/// Cross-family abstraction for layout and template selection in renderer crates.
30#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
31pub enum GenericCategory {
32 /// Schema or message type pages.
33 Schema,
34 /// RPC or HTTP operation pages.
35 Operation,
36 /// Service definition pages.
37 Service,
38 /// Fallback for categories without specialized rendering.
39 Generic,
40}