diff --git a/src/main.rs b/src/main.rs index e3198c0..f82ac53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ fn main() -> Result<(), io::Error> { let mut entries = vec![]; for line in io::BufReader::new(file).lines().flatten() { - let entry: nixtract::NixtractEntry = serde_json::from_str(&line.trim()).unwrap(); + let entry: nixtract::NixtractEntry = serde_json::from_str(line.trim()).unwrap(); entries.push(entry); } let nixtract: Nixtract = Nixtract { entries }; diff --git a/src/model.rs b/src/model.rs index c2a2fe9..05a3376 100644 --- a/src/model.rs +++ b/src/model.rs @@ -54,17 +54,17 @@ pub(crate) struct ModelDependency { pub(crate) depends_on: Vec, } -impl Into for ModelType { - fn into(self) -> String { - match self { +impl From for String { + fn from(val: ModelType) -> Self { + match val { ModelType::Application => "application".to_owned(), } } } -impl Into for ModelExternalReferenceType { - fn into(self) -> String { - match self { +impl From for String { + fn from(val: ModelExternalReferenceType) -> Self { + match val { ModelExternalReferenceType::Website => "website".to_owned(), } } diff --git a/src/nixtract.rs b/src/nixtract.rs index d59b995..b65a79c 100644 --- a/src/nixtract.rs +++ b/src/nixtract.rs @@ -3,6 +3,9 @@ //! - Parsing the incoming output of Nixtract //! - Converting that input into the internal representation of Genealogos +// In this module, one might see that we do deserialize unused fields. This is +// to ensure we stay complient with nixtract output. + use serde::Deserialize; use crate::model::{ @@ -17,11 +20,15 @@ pub(crate) struct Nixtract { #[derive(Deserialize, Debug)] pub(crate) struct NixtractEntry { - pub(crate) attribute_path: String, - pub(crate) derivation_path: String, + #[serde(rename(deserialize = "attribute_path"))] + pub(crate) _attribute_path: String, + #[serde(rename(deserialize = "derivation_path"))] + pub(crate) _derivation_path: String, pub(crate) output_path: String, - pub(crate) outputs: Vec, - pub(crate) name: String, + #[serde(rename(deserialize = "outputs"))] + pub(crate) _outputs: Vec, + #[serde(rename(deserialize = "name"))] + pub(crate) _name: String, pub(crate) parsed_name: NixtractParsedName, pub(crate) nixpkgs_metadata: NixtractNixpkgsMetadata, pub(crate) build_inputs: Vec, @@ -29,22 +36,27 @@ pub(crate) struct NixtractEntry { #[derive(Deserialize, Debug)] pub(crate) struct NixtractOutput { - pub(crate) name: String, - pub(crate) output_path: String, + #[serde(rename(deserialize = "name"))] + pub(crate) _name: String, + #[serde(rename(deserialize = "output_path"))] + pub(crate) _output_path: String, } #[derive(Deserialize, Debug)] pub(crate) struct NixtractParsedName { pub(crate) name: String, - pub(crate) version: String, + #[serde(rename(deserialize = "version"))] + pub(crate) _version: String, } #[derive(Deserialize, Debug)] pub(crate) struct NixtractNixpkgsMetadata { pub(crate) description: String, - pub(crate) pname: String, + #[serde(rename(deserialize = "pname"))] + pub(crate) _pname: String, pub(crate) version: String, - pub(crate) broken: bool, + #[serde(rename(deserialize = "broken"))] + pub(crate) _broken: bool, pub(crate) homepage: String, pub(crate) licenses: Option>, } @@ -58,8 +70,10 @@ pub(crate) struct NixtractLicense { #[derive(Deserialize, Debug)] pub(crate) struct NixtractBuiltInput { - pub(crate) attribute_path: String, - pub(crate) build_input_type: String, + #[serde(rename(deserialize = "attribute_path"))] + pub(crate) _attribute_path: String, + #[serde(rename(deserialize = "build_input_type"))] + pub(crate) _build_input_type: String, pub(crate) output_path: Option, } @@ -83,7 +97,7 @@ impl From for Model { .nixpkgs_metadata .licenses .as_ref() - .map(|v| v.into_iter().map(Into::into).collect()); + .map(|v| v.iter().map(Into::into).collect()); ModelComponent { r#type: ModelType::Application,