31 lines
1.3 KiB
Rust
31 lines
1.3 KiB
Rust
use crate::deserialize::util::unwrap_single_member_hash;
|
|
use crate::spec::polymorphic_pass_through_spec::{PolymorphicPassThroughBuildSpec, PolymorphicPassThroughVariant};
|
|
use yaml_rust2::Yaml;
|
|
|
|
pub fn deserialize_polymorphic_pass_through(name: &str, props: &Yaml) -> PolymorphicPassThroughBuildSpec {
|
|
let build_kind = props["build"]["kind"].as_str().unwrap();
|
|
let variants = props["variants"].as_vec().unwrap()
|
|
.iter()
|
|
.map(|variant_yaml| {
|
|
let (variant_name, variant_props) = unwrap_single_member_hash(variant_yaml);
|
|
if variant_props["inner"].is_hash() {
|
|
let inner_kind = variant_props["inner"]["kind"].as_str().unwrap();
|
|
PolymorphicPassThroughVariant::Inner {
|
|
name: variant_name,
|
|
kind: inner_kind.to_string(),
|
|
}
|
|
} else if variant_props["pass_through"].is_hash() {
|
|
let pass_through_kind = variant_props["pass_through"]["kind"].is_hash();
|
|
PolymorphicPassThroughVariant::PassThrough {
|
|
name: variant_name,
|
|
kind: pass_through_kind.to_string(),
|
|
}
|
|
} else {
|
|
panic!()
|
|
}
|
|
})
|
|
.map(Box::new)
|
|
.collect();
|
|
PolymorphicPassThroughBuildSpec::new(name, build_kind, variants)
|
|
}
|