Skip to main content

Rust

The cimvocabcheck crate validates SPARQL queries and SHACL shapes from Rust. It is a binding, not a second implementation: it drives the CLI and parses its report, so a finding it returns is the same finding the editors, the CI job and any other language binding produce.

[dependencies]
cimvocabcheck = "1"

Rust 1.74+. serde is the whole dependency list — the subprocess timeout included, everything else is std. It does need an engine to drive — see Finding an engine.

Validating​

use cimvocabcheck::{validate, Options};

let report = validate(
&["queries/line-segments.rq", "shapes/equipment.ttl"],
&Options::new().schema("profiles"),
)?;

for finding in report.errors() {
println!("{finding}"); // queries/line-segments.rq:3:12: ERROR[UNKNOWN_CLASS] …
}

Findings are data, not errors. A file with errors comes back as a report whose ok() is false; Error is reserved for "the engine could not run, or could not be trusted".

One call, every input​

Loading a CGMES profile set costs about a second, and validating one more query after that costs almost nothing — so validate takes a slice and returns one report. Spawning the engine per file turns a one-second job into a one-second-per-file job. validate_text validates a query held in memory by passing it on stdin; because the engine tells SHACL from SPARQL by file suffix, shapes have to come from a file.

Options​

Options::new()
.schema("profiles") // RDFS file(s) or directories; or …
.config("opencgmes.jsonc") // … a config file; or …
.endpoint("http://localhost:3030/ds/query") // … a SPARQL endpoint
.profile("http://iec.ch/TC57/ns/CIM/CoreEquipment-EU/3.0")
.strictness(Strictness::STRICT) // permissive | default | strict | pedantic
.verbose(false) // WARN/INFO are included by default
.cwd("…")
.timeout(Duration::from_secs(120))

With no schema, config or endpoint the engine discovers the nearest opencgmes.jsonc above the working directory; without one it checks syntax only.

Pass inputs relative to cwd: they appear verbatim in the report, and CI annotations only line up with a source tree when they are repository-relative.

verbose defaults to true, unlike the CLI. A library hands everything back and lets the caller filter, rather than discarding findings the caller cannot then recover.

The result​

report.ok()no input has an ERROR
report.summarycounts, matching exactly what this report contains
report.resultsone FileResult per input, in the order they were passed
report.errors() / warnings() / infos()flat findings, each carrying the file it came from
report.of_code(…) / at_least(…)the same, narrowed
report.for_file(path)one input's result
report.tool.versionwhich engine produced this

Match on code, never on message: messages change between releases, codes do not.

let typos = [Code::UNKNOWN_CLASS, Code::UNKNOWN_PROPERTY]
.iter()
.flat_map(|code| report.of_code(code))
.collect::<Vec<_>>();

Finding an engine​

discover searches in this order, and the error names every place it looked:

#Source
1Options::engine / engine_pathan Engine, or a path to a JAR or binary
2$CIMVOCABCHECK_JAR, then $CIMVOCABCHECK_BINa fat JAR (run with java), or an executable
3cimvocabcheck on PATH
4docker run ghcr.io/soptim/cimvocabcheck-cli:<tag>last resort, with the engine image of the binding's own version: :1.2.0 for 1.2.0, :1.2.0-rc.1 for a release candidate, :edge (built from main) for a development build. Never :latest, which would change the engine under an unchanged binding

A JAR engine needs a JRE 21 or newer, found via JAVA_HOME or PATH. A local engine is never started under an ASCII-only locale: when the effective one (LC_ALL, else LC_CTYPE, else LANG) is C, POSIX or unset, as in many containers and CI images, the engine gets C.UTF-8 so it can open non-ASCII file names. It does too when a locale the environment names is not installed (LANG=en_US.UTF-8 without the locale package, going by locale -a): the C library then falls back to C for every category, so the engine gets LC_ALL=C.UTF-8.

The Docker fallback mounts the working directory at the image's /work and anything else it has to read under /host — see the Python page for the shared details, which are the same for every binding.

Errors​

VariantWhen
EngineNotFoundnothing to run; carries every location that was searched
EngineMissinga configured engine path does not exist
Toolthe engine reported a usage/config failure (exit 2), or failed outright
ReportParseoutput was not a report of the contract major this crate targets
Timeoutthe engine did not finish in time
UnreachablePatha path the Docker engine cannot reach: a schema or config outside the working directory that does not exist, a Windows path a config names, or one that would land on a directory of the image itself

Error::failure() returns the command, exit code, stdout and stderr.

Versions and compatibility​

The crate tracks the engine it was generated against (1.2.x crate ↔ 1.2.x engine) and accepts any engine declaring the same report contract major. Within a major the contract only ever adds, so the crate keeps fields it does not know in each type's extra map and accepts codes it does not know — Annotation::is_known_code tells you which.

The public structs and enums are #[non_exhaustive], so a new contract field, engine kind or option arrives in a minor version rather than a major one. Read their fields freely, but match with a _ arm and .., and build them with Engine::docker(…), Discovery::new() and Options::new() rather than struct literals.

The model is generated from the published JSON Schema by the generator shared with the Python and .NET bindings; CI fails when the two have drifted apart.