Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
libyang
A YANG parser and data-modeling library written in Rust.
YANG (RFC 7950) is the data
modeling language used to describe configuration and state data for network
management protocols such as NETCONF and RESTCONF. libyang parses YANG
modules, resolves their dependencies, and turns them into a tree you can walk
to drive configuration and validation.
Features
- RFC 7950 grammar, parsed with a
parol-generated parser. - Module loading with automatic
import/include(submodule) resolution. typedef,grouping,identity, andunionresolution.- An
Entrytree suitable for building config schemas and validators. - Deterministic output: the tree has the same shape on every run, so it can be diffed or used to generate golden files.
- Errors and schema problems are returned, never printed.
Installation
Add it to your Cargo.toml:
[]
= "2"
Usage
Load a module by name from a search path, resolve its dependencies, and build
the Entry tree:
use ;
let mut store = new;
store.add_path; // directory containing your .yang files
// Parse the module and everything it imports/includes.
store.read_with_resolve.expect;
store.identity_resolve;
let module = store.find_module.expect;
let entry = to_entry;
println!;
For low-level access, you can parse a single file into the grammar AST directly:
use yang;
use YangGrammar;
use parse;
let input = read_to_string.unwrap;
let mut grammar = new;
parse.expect;
let node = yang.expect;
Diagnostics
A malformed augment — a target that does not resolve, one that lands on a
leaf, or one that introduces a name the target already has — does not stop the
build: the tree is still produced with that augment skipped. Those findings are
collected on the store rather than written to stderr, so the caller decides
whether to log them, fail, or ignore them:
use ;
let mut store = new;
store.add_path;
store.read_with_resolve.expect;
store.identity_resolve;
let module = store.find_module.expect;
let entry = to_entry;
for diagnostic in store.take_diagnostics
Each Diagnostic names the module at fault along with the target and the
offending node, and can be matched on rather than parsed.
Migrating from 1.x
2.0 is a breaking release:
YangStore::readis gone. Useread_with_resolve, which loads each module once (so mutually importing modules terminate) and keeps submodules.YangStore::modulesandsubmodulesare private. Usefind_module/find_submodule.YangError's variants carry the file, module and underlying parse diagnostic, and the enum is#[non_exhaustive]. Parse failures are returned instead of being printed to stdout.- Augment problems are collected as
Diagnostics (see above) instead of being written to stderr. RangeNodeimplementsDisplayinstead of having an inherentto_string;.to_string()still works.
How it works
The pipeline runs in four stages:
- Parse — YANG text is parsed by the
parol-generated grammar into aYangGrammarAST. - AST —
yang()converts the grammar tree into structuredNodevalues. - Resolve —
YangStoreloads imports and includes, keeping submodules addressable throughfind_submodule, and resolves typedefs, groupings, and identities. Modules that import each other are loaded once, so cycles terminate. - Entry —
to_entry()produces anEntrytree for data modeling and validation.
Testing
Integration tests live in tests/ and run against fixture modules in
tests/yang/ and the standard modules in yang/.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.