Skip to main content

Crate vastlint_core

Crate vastlint_core 

Source
Expand description

§vastlint-core

A zero-I/O VAST XML validation library. Takes a VAST XML string and returns a structured ValidationResult listing every issue found, the detected VAST version, and a summary of error/warning/info counts.

The entire public surface is two functions and a handful of types:

  • validate – validate with default settings (most callers want this)
  • validate_with_context – validate with rule overrides or wrapper depth
  • fix – fix deterministic issues and return repaired XML
  • fix_with_context – fix with rule overrides or wrapper depth
  • all_rules – list the full 118-rule catalog

§Performance — allocator recommendation

vastlint-core builds an owned document tree on every call (one heap allocation per XML element, attribute, and text node). Under concurrent load the system allocator becomes a bottleneck because all threads compete for a shared free-list lock.

Switching to mimalloc in your binary crate eliminates this contention and gives dramatically better throughput at high concurrency, especially for larger documents:

# Cargo.toml (your binary, not a library crate)
[dependencies]
mimalloc = { version = "0.1", default-features = false }
// src/main.rs
use mimalloc::MiMalloc;
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

Measured on Apple M4 (10 threads, production-realistic VAST tags):

Allocator17 KB tag44 KB tag
system (default)1,847 tags/s · 541 µs328 tags/s · 3,048 µs
mimalloc15,760 tags/s · 63 µs2,635 tags/s · 380 µs

mimalloc: ~8× throughput improvement on multi-threaded workloads.

⚠️ Do not set a global allocator in a library crate — it would override the allocator for any host process that links you (Go, Python, Ruby runtimes, etc.), which can cause heap corruption.

§Quick start

let xml = r#"<VAST version="2.0">
  <Ad><InLine>
    <AdSystem>Demo</AdSystem>
    <AdTitle>Ad</AdTitle>
    <Impression>https://t.example.com/imp</Impression>
    <Creatives>
      <Creative>
        <Linear>
          <Duration>00:00:15</Duration>
          <MediaFiles>
            <MediaFile delivery="progressive" type="video/mp4"
                       width="640" height="360">
              https://cdn.example.com/ad.mp4
            </MediaFile>
          </MediaFiles>
        </Linear>
      </Creative>
    </Creatives>
  </InLine></Ad>
</VAST>"#;

let result = vastlint_core::validate(xml);
assert_eq!(result.summary.errors, 0);

§Design constraints

The library has no I/O, no logging, no global state, and no async runtime. It can be embedded in a CLI, HTTP server, WASM module, or FFI binding without pulling in any platform-specific dependencies.

Three crate dependencies: quick-xml (XML parsing), url (RFC 3986), and phf (compile-time hash maps).

Structs§

AppliedFix
A single fix that was successfully applied to the document.
FixResult
The result of a fix or fix_with_context call.
Issue
A single validation finding.
RuleMeta
Metadata about a single rule, as exposed by the public catalog.
Summary
Counts of issues by severity.
ValidationContext
Context passed to validate_with_context. All fields have safe defaults.
ValidationResult
The full result of validating a VAST document.

Enums§

DetectedVersion
How the version was determined.
RuleLevel
Per-rule severity override. Mirrors Severity but adds Off.
RuleSource
The external standard or authority that a rule is derived from.
Severity
Issue severity, based strictly on spec language.
VastVersion
The VAST version as declared in the version attribute or inferred from document structure.

Functions§

all_rules
Returns the full catalog of known rules in definition order.
fix
Fix a VAST XML string using default settings.
fix_with_context
Fix a VAST XML string with caller-supplied context.
validate
Validate a VAST XML string using default settings.
validate_with_context
Validate a VAST XML string with caller-supplied context.