Crates.io | yang3 |
lib.rs | yang3 |
version | |
source | src |
created_at | 2024-07-08 16:32:51.694921 |
updated_at | 2024-10-23 23:47:42.685508 |
description | libyang3 bindings for Rust |
homepage | |
repository | https://github.com/holo-routing/yang-rs |
max_upload_size | |
id | 1296141 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Rust bindings for the libyang library.
For raw FFI bindings for libyang, see libyang3-sys.
[dependencies]
yang3 = "0.10"
By default, yang-rs uses pre-generated FFI bindings and uses dynamic linking to load libyang. The following feature flags, however, can be used to change that behavior:
A basic example that parses and validates JSON instance data, and then converts it to the XML format:
use std::fs::File;
use yang3::context::{Context, ContextFlags};
use yang3::data::{
Data, DataFormat, DataParserFlags, DataPrinterFlags, DataTree,
DataValidationFlags,
};
static SEARCH_DIR: &str = "./assets/yang/";
fn main() -> std::io::Result<()> {
// Initialize context.
let mut ctx = Context::new(ContextFlags::NO_YANGLIBRARY)
.expect("Failed to create context");
ctx.set_searchdir(SEARCH_DIR)
.expect("Failed to set YANG search directory");
// Load YANG modules.
for module_name in &["ietf-interfaces", "iana-if-type"] {
ctx.load_module(module_name, None, &[])
.expect("Failed to load module");
}
// Parse and validate data tree in the JSON format.
let dtree = DataTree::parse_file(
&ctx,
File::open("./assets/data/interfaces.json")?,
DataFormat::JSON,
DataParserFlags::empty(),
DataValidationFlags::NO_STATE,
)
.expect("Failed to parse data tree");
// Print data tree in the XML format.
dtree
.print_file(
std::io::stdout(),
DataFormat::XML,
DataPrinterFlags::WD_ALL | DataPrinterFlags::WITH_SIBLINGS,
)
.expect("Failed to print data tree");
Ok(())
}
Note the NO_STATE
flag passed to parse_file
since the example json file does not contain state data.
More examples can be found here.
This project is licensed under the MIT license.
Bug reports and pull requests are welcome on GitHub at https://github.com/holo-routing/yang-rs.