Skip to main content

wowlab_docgen_cli/infra/metadata/
model.rs

1use std::collections::BTreeMap;
2
3#[derive(Clone, Debug, Default)]
4// #t(rust_similar_structs) metadata target records are parser output rather than template-facing Cargo rows
5pub struct BinTarget {
6    pub name: String,
7    pub required_features: Vec<String>,
8}
9
10#[derive(Clone, Debug, Default)]
11// #t(rust_similar_structs) package metadata scripts are source records distinct from rendered script and alias rows
12pub struct Script {
13    pub name: String,
14    pub command: String,
15}
16
17#[derive(Clone, Debug, Default, serde::Serialize)]
18pub struct ExternalDep {
19    pub name: String,
20    pub version: String,
21}
22
23/// An internal Cargo dependency resolved to a workspace-relative link.
24#[derive(Clone, Debug, Default, Eq, PartialEq)]
25pub struct WorkspaceDep {
26    pub path: String,
27    pub optional: bool,
28    pub features: Vec<String>,
29    pub default_features: Option<bool>,
30}
31
32#[derive(Debug, Default)]
33pub struct Metadata {
34    pub name: Option<String>,
35    pub description: Option<String>,
36    pub workspace_deps: BTreeMap<String, WorkspaceDep>,
37    pub features: BTreeMap<String, Vec<String>>,
38    pub has_binary: bool,
39    pub binary_name: Option<String>,
40    pub kind: PackageKind,
41    pub bins: Vec<BinTarget>,
42    pub tests: Vec<String>,
43    pub benches: Vec<String>,
44    pub examples: Vec<String>,
45    pub scripts: Vec<Script>,
46    pub external_deps: Vec<ExternalDep>,
47    pub version: String,
48    pub msrv: String,
49}
50
51#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
52#[non_exhaustive]
53pub enum PackageKind {
54    #[default]
55    Unknown,
56    RustCrate,
57    NodePackage,
58    Directory,
59}
60
61impl PackageKind {
62    #[must_use]
63    pub fn as_str(&self) -> &'static str {
64        match self {
65            Self::RustCrate => "crate",
66            Self::NodePackage => "package",
67            Self::Directory => "directory",
68            Self::Unknown => "unknown",
69        }
70    }
71}