Skip to main content

rustnetconf_yang/
lib.rs

1//! # rustnetconf-yang
2//!
3//! Compile-time typed Rust structs generated from YANG models, for use with
4//! [`rustnetconf`]. The generated types serialize to NETCONF-ready XML.
5//!
6//! ## Quick start
7//!
8//! The generated code is behind the **`generated`** feature, which is **off by
9//! default**. You must enable it or the `ietf_*` modules will not exist:
10//!
11//! ```toml
12//! [dependencies]
13//! rustnetconf-yang = { version = "0.1", features = ["generated"] }
14//! ```
15//!
16//! Then use a bundled model:
17//!
18//! ```rust,ignore
19//! use rustnetconf_yang::ietf_interfaces::{Interfaces, Interface};
20//! use rustnetconf_yang::serialize::ToNetconfXml;
21//!
22//! let config = Interfaces {
23//!     interface: vec![Interface {
24//!         name: Some("eth0".into()),
25//!         description: Some("uplink".into()),
26//!         enabled: Some(true),
27//!         ..Default::default()
28//!     }],
29//! };
30//!
31//! // Serialize to NETCONF-ready XML for `edit-config`:
32//! let xml = config.to_xml().unwrap();
33//! ```
34//!
35//! ## Which models are available?
36//!
37//! The crate **bundles** these IETF models, generated at build time:
38//!
39//! - `ietf_interfaces` (from `ietf-interfaces.yang`)
40//! - `ietf_ip` (from `ietf-ip.yang`)
41//! - plus supporting types from `ietf-yang-types` / `ietf-inet-types`
42//!
43//! Each module exposes a `NAMESPACE` const and structs named in `PascalCase`
44//! after the YANG nodes (e.g. container `interfaces` -> `Interfaces`, list
45//! `interface` -> `Interface`). YANG names that are Rust keywords are suffixed
46//! with `_` (e.g. leaf `type` -> field `type_`).
47//!
48//! ## Using your own YANG models
49//!
50//! Code is generated from the `yang-models/` directory **of this crate**, not
51//! of your project: the build script reads `$CARGO_MANIFEST_DIR/yang-models`,
52//! which resolves to this crate's source in the Cargo registry cache when used
53//! as a dependency. To generate types from custom `.yang` files you must vendor
54//! this crate (e.g. a git/path dependency or fork) and add your models to its
55//! `yang-models/` directory.
56//!
57//! [`rustnetconf`]: https://docs.rs/rustnetconf
58
59pub mod serialize;
60
61// Re-export generated types when available
62// The build.rs generates code into OUT_DIR, which is included here.
63#[cfg(feature = "generated")]
64include!(concat!(env!("OUT_DIR"), "/yang_generated.rs"));