use resand::traits::IntoNode;
use resand_derive::{FromNode, IntoNode};
#[derive(Debug, IntoNode, FromNode)]
pub struct Certificate {
#[resand(attr)]
pub src: String,
}
#[derive(Debug, IntoNode, FromNode)]
pub struct TrustAnchor {
#[resand(child, many)]
pub certificates: Vec<Certificate>,
}
#[derive(Debug, IntoNode, FromNode)]
pub struct DebugOverride {
#[resand(child)]
pub trust_anchors: TrustAnchor,
}
#[derive(Debug, IntoNode, FromNode)]
pub struct BaseConfig {
#[resand(attr)]
pub cleartext_traffic_permitted: bool,
#[resand(child)]
pub trust_anchors: TrustAnchor,
}
#[derive(Debug, IntoNode, FromNode)]
#[resand(name = "network-security-config")]
pub struct NetworkSecurityConfig {
#[resand(child)]
pub debug_overrides: DebugOverride,
#[resand(child)]
pub base_config: BaseConfig,
}
fn main() {
let tree = NetworkSecurityConfig {
debug_overrides: DebugOverride {
trust_anchors: TrustAnchor {
certificates: vec![Certificate {
src: "user".to_string(),
}],
},
},
base_config: BaseConfig {
cleartext_traffic_permitted: true,
trust_anchors: TrustAnchor {
certificates: vec![
Certificate {
src: "system".to_string(),
},
Certificate {
src: "user".to_string(),
},
],
},
},
}
.into_tree();
dbg!(&tree);
let mut file = std::fs::File::create("path/to/network_security_config.xml").unwrap();
tree.write(&mut file).unwrap();
}