cmake_file_api/
objects.rs

1use serde::{Deserialize, Serialize};
2
3pub mod cache_v2;
4pub mod cmake_files_v1;
5pub mod codemodel_v2;
6pub mod configure_log_v1;
7pub mod toolchains_v1;
8
9pub use cache_v2::Cache as CacheV2;
10pub use cmake_files_v1::CMakeFiles as CMakeFilesV1;
11pub use codemodel_v2::CodeModel as CodeModelV2;
12pub use configure_log_v1::ConfigureLog as ConfigureLogV1;
13pub use toolchains_v1::Toolchains as ToolchainsV1;
14
15use crate::reply;
16
17#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19#[non_exhaustive]
20pub struct MajorMinor {
21    pub major: u32,
22    pub minor: u32,
23}
24
25#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
26#[non_exhaustive]
27pub enum ObjectKind {
28    #[default]
29    #[serde(rename = "codemodel")]
30    CodeModel,
31    #[serde(rename = "toolchains")]
32    Toolchains,
33    #[serde(rename = "cache")]
34    Cache,
35    #[serde(rename = "cmakeFiles")]
36    CMakeFiles,
37    #[serde(rename = "configureLog")]
38    ConfigureLog,
39}
40
41impl ObjectKind {
42    #[must_use]
43    pub fn as_str(&self) -> &'static str {
44        match self {
45            ObjectKind::CodeModel => "codemodel",
46            ObjectKind::Toolchains => "toolchains",
47            ObjectKind::Cache => "cache",
48            ObjectKind::CMakeFiles => "cmakeFiles",
49            ObjectKind::ConfigureLog => "configureLog",
50        }
51    }
52}
53
54pub trait Object {
55    fn kind() -> ObjectKind;
56    fn major() -> u32;
57
58    /// Resolve references in the object
59    ///
60    /// Some objects contain references to other json files. This method is called after the object
61    /// is deserialized to resolve these references.
62    /// Currently only the codemodel-v2 object has references (targets, directories) that need to be resolved.
63    ///
64    /// # Errors
65    ///
66    /// `ReaderError::IO`: if an IO error occurs while reading the object file
67    /// `ReaderError::Parse`: if an error occurs while parsing the object file
68    fn resolve_references(&mut self, _: &reply::Reader) -> Result<(), reply::ReaderError> {
69        Ok(())
70    }
71}