konjure_sdk/lib.rs
1//! Portable deterministic Konjure SDK core. The compiler is optional; runtime
2//! consumers can build `--no-default-features` and load validated documents.
3//!
4//! Construct or [`compile`] a [`SceneDocument`], validate untrusted documents
5//! with [`validate`], then create a [`Runtime`] to sample frames or dispatch
6//! declared actions. The core owns its scene and derived mesh allocations; it
7//! performs no I/O, rendering, clock reads, or external effects.
8//!
9//! ```
10//! use konjure_sdk::{compile, Runtime};
11//! let runtime = Runtime::new(compile("scene dot { node star { sphere 0.2m; color #ffffff; } }")?)?;
12//! assert_eq!(runtime.sample(0.0)?.draws.len(), 1);
13//! # Ok::<(), konjure_sdk::Diagnostic>(())
14//! ```
15#![cfg_attr(not(feature = "std"), no_std)]
16#![deny(missing_docs)]
17extern crate alloc;
18/// Exact numeric values, immutable buffers, tensors, and validated media payloads.
19pub mod data;
20/// Scene documents, observations, identifiers, diagnostics, and SDK limits.
21pub mod domain;
22/// Deterministic tessellation of built-in scene geometry.
23pub mod geometry;
24#[cfg(feature = "compiler")]
25mod parser;
26/// Portable semantic UI documents and explicit per-view presentation routing.
27pub mod presentation;
28/// Ordered, side-effect-free recordings of runtime decisions.
29pub mod recording;
30/// Headless scene evaluation, action dispatch, and frame output.
31pub mod runtime;
32/// Structural and numeric validation for untrusted scene documents.
33pub mod validation;
34pub use domain::*;
35pub use geometry::*;
36pub use presentation::*;
37pub use recording::*;
38pub use runtime::*;
39pub use validation::validate;
40#[cfg(feature = "compiler")]
41/// Compiles bounded Konjure DSL source into a validated scene document.
42///
43/// The compiler allocates tokens and document-owned strings and reports source
44/// locations in [`Diagnostic::span`] when parsing fails. It does not perform
45/// I/O or execute actions.
46///
47/// # Errors
48///
49/// Returns a diagnostic for invalid syntax, unsupported units, source larger
50/// than [`MAX_SOURCE_BYTES`], or a document rejected by [`validate`].
51pub fn compile(source: &str) -> Result<SceneDocument, Diagnostic> {
52 parser::compile(source)
53}
54#[cfg(not(feature = "compiler"))]
55/// Reports that compilation is unavailable because the `compiler` feature is disabled.
56///
57/// Consumers built without the compiler can deserialize and [`validate`] a
58/// document supplied by another trusted boundary instead.
59///
60/// # Errors
61///
62/// Always returns a diagnostic explaining that the compiler feature is disabled.
63pub fn compile(_: &str) -> Result<SceneDocument, Diagnostic> {
64 Err(Diagnostic::plain("the compiler feature is disabled"))
65}
66#[cfg(test)]
67mod tests;