Skip to main content

compatdb_core/
docs.rs

1//! Links into this crate's published rustdoc, for a launcher's templates and
2//! messages. Every link starts with [`DOCS_URL`](crate::DOCS_URL).
3
4use crate::Key;
5
6/// A section of the crate's front page, the spec of the format and the rules.
7///
8/// Each variant is one heading of that page; [`DocSection::url`] links to it.
9#[non_exhaustive]
10#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
11pub enum DocSection {
12    /// Quick start: how a launcher builds its rules and starts Wine with them.
13    QuickStart,
14    /// Format: the text of `WINE_COMPATDB`.
15    Format,
16    /// Strict and lenient parsing: how the text is read, a part of Format.
17    StrictAndLenientParsing,
18    /// Matching: which processes a rule applies to.
19    Matching,
20    /// Folding: how the rules that match a process combine.
21    Folding,
22    /// Keys: the fields of a rule.
23    Keys,
24    /// Built-in rules: the rules `compatdb.so` has compiled in.
25    BuiltInRules,
26    /// Recipes: one rule for each common goal.
27    Recipes,
28    /// Launcher responsibilities: what a launcher does beyond the rules.
29    LauncherResponsibilities,
30}
31
32/// The link to the heading whose rustdoc id is `$anchor`.
33macro_rules! section {
34    ($anchor:literal) => {
35        concat!(docs_url!(), "#", $anchor)
36    };
37}
38
39/// The link to the doc of the variant `$variant` of [`Key`].
40macro_rules! variant {
41    ($variant:ident) => {
42        concat!(docs_url!(), "enum.Key.html#variant.", stringify!($variant))
43    };
44}
45
46impl DocSection {
47    /// Every section, in the order of the page.
48    pub const ALL: &'static [Self] = &[
49        Self::QuickStart,
50        Self::Format,
51        Self::StrictAndLenientParsing,
52        Self::Matching,
53        Self::Folding,
54        Self::Keys,
55        Self::BuiltInRules,
56        Self::Recipes,
57        Self::LauncherResponsibilities,
58    ];
59
60    /// The full URL of the section's heading.
61    #[must_use]
62    pub const fn url(self) -> &'static str {
63        match self {
64            Self::QuickStart => section!("quick-start"),
65            Self::Format => section!("format"),
66            Self::StrictAndLenientParsing => section!("strict-and-lenient-parsing"),
67            Self::Matching => section!("matching"),
68            Self::Folding => section!("folding"),
69            Self::Keys => section!("keys"),
70            Self::BuiltInRules => section!("built-in-rules"),
71            Self::Recipes => section!("recipes"),
72            Self::LauncherResponsibilities => section!("launcher-responsibilities"),
73        }
74    }
75}
76
77impl Key {
78    /// The full URL of this key's doc, the doc of its variant of [`Key`].
79    #[must_use]
80    pub const fn docs_url(self) -> &'static str {
81        match self {
82            Self::Exe => variant!(Exe),
83            Self::Company => variant!(Company),
84            Self::Product => variant!(Product),
85            Self::OriginalFilename => variant!(OriginalFilename),
86            Self::Dxgi => variant!(Dxgi),
87            Self::D3d9 => variant!(D3d9),
88            Self::Wined3d => variant!(Wined3d),
89            Self::OpenGl => variant!(OpenGl),
90            Self::DpiAware => variant!(DpiAware),
91            Self::LargeAddressAware => variant!(LargeAddressAware),
92            Self::Gcmouse => variant!(Gcmouse),
93            Self::ForceNx => variant!(ForceNx),
94            Self::MetalHud => variant!(MetalHud),
95            Self::DllOverrides => variant!(DllOverrides),
96            Self::ArgumentsOverride => variant!(ArgumentsOverride),
97            Self::Arguments => variant!(Arguments),
98            Self::DebugChannels => variant!(DebugChannels),
99            Self::Env => variant!(Env),
100        }
101    }
102}
103
104#[cfg(test)]
105mod tests;