Skip to main content

nativeview_cli/manifest/
docs.rs

1//! Declarative `[docs]` section of `nativeview.toml` (`#[serde(deny_unknown_fields)]`) for
2//! `nv docs check|build|dev` site package and content directory defaults.
3
4use serde::Deserialize;
5
6use super::{ManifestError, validate_non_empty_label, validate_rel_path_inner};
7
8/// Validated `[docs]` section of `nativeview.toml`.
9#[derive(Debug, Default, Clone, PartialEq, Eq)]
10pub struct DocsSection {
11    /// Cargo package name exposing the docs site binary (overridden by `--site-package`).
12    pub site_package: Option<String>,
13    /// Relative path to the docs content directory (overridden by `--content`).
14    pub content: Option<String>,
15}
16
17#[derive(Debug, Default, Deserialize)]
18#[serde(deny_unknown_fields)]
19pub(super) struct RawDocsSection {
20    site_package: Option<String>,
21    content: Option<String>,
22}
23
24pub(super) fn parse_docs_section(
25    raw: Option<RawDocsSection>,
26) -> Result<Option<DocsSection>, ManifestError> {
27    let Some(raw) = raw else {
28        return Ok(None);
29    };
30    let site_package = raw
31        .site_package
32        .as_deref()
33        .map(|v| validate_non_empty_label("docs.site_package", v))
34        .transpose()?;
35    let content = raw
36        .content
37        .as_deref()
38        .map(|v| validate_rel_path_inner("docs.content", v, true))
39        .transpose()?;
40    Ok(Some(DocsSection {
41        site_package,
42        content,
43    }))
44}