Skip to main content

Crate rustnetconf_yang

Crate rustnetconf_yang 

Source
Expand description

§rustnetconf-yang

Compile-time typed Rust structs generated from YANG models, for use with rustnetconf. The generated types serialize to NETCONF-ready XML.

§Quick start

The generated code is behind the generated feature, which is off by default. You must enable it or the ietf_* modules will not exist:

[dependencies]
rustnetconf-yang = { version = "0.1", features = ["generated"] }

Then use a bundled model:

use rustnetconf_yang::ietf_interfaces::{Interfaces, Interface};
use rustnetconf_yang::serialize::ToNetconfXml;

let config = Interfaces {
    interface: vec![Interface {
        name: Some("eth0".into()),
        description: Some("uplink".into()),
        enabled: Some(true),
        ..Default::default()
    }],
};

// Serialize to NETCONF-ready XML for `edit-config`:
let xml = config.to_xml().unwrap();

§Which models are available?

The crate bundles these IETF models, generated at build time:

  • ietf_interfaces (from ietf-interfaces.yang)
  • ietf_ip (from ietf-ip.yang)
  • plus supporting types from ietf-yang-types / ietf-inet-types

Each module exposes a NAMESPACE const and structs named in PascalCase after the YANG nodes (e.g. container interfaces -> Interfaces, list interface -> Interface). YANG names that are Rust keywords are suffixed with _ (e.g. leaf type -> field type_).

§Using your own YANG models

Code is generated from the yang-models/ directory of this crate, not of your project: the build script reads $CARGO_MANIFEST_DIR/yang-models, which resolves to this crate’s source in the Cargo registry cache when used as a dependency. To generate types from custom .yang files you must vendor this crate (e.g. a git/path dependency or fork) and add your models to its yang-models/ directory.

Modules§

serialize
XML serialization helpers for YANG-generated types.