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;
24pub mod interchange;
25#[cfg(feature = "compiler")]
26mod parser;
27/// Portable semantic UI documents and explicit per-view presentation routing.
28pub mod presentation;
29/// Bounded procedural meshes and pure mesh transforms.
30pub mod procedural;
31/// Ordered, side-effect-free recordings of runtime decisions.
32pub mod recording;
33/// Headless scene evaluation, action dispatch, and frame output.
34pub mod runtime;
35/// Structural and numeric validation for untrusted scene documents.
36pub mod validation;
37pub use domain::*;
38pub use geometry::*;
39pub use presentation::*;
40pub use procedural::*;
41pub use recording::*;
42pub use runtime::*;
43pub use validation::validate;
44#[cfg(feature = "compiler")]
45/// Compiles bounded Konjure DSL source into a validated scene document.
46///
47/// The compiler allocates tokens and document-owned strings and reports source
48/// locations in [`Diagnostic::span`] when parsing fails. It does not perform
49/// I/O or execute actions.
50///
51/// # Errors
52///
53/// Returns a diagnostic for invalid syntax, unsupported units, source larger
54/// than [`MAX_SOURCE_BYTES`], or a document rejected by [`validate`].
55pub fn compile(source: &str) -> Result<SceneDocument, Diagnostic> {
56 parser::compile(source)
57}
58#[cfg(not(feature = "compiler"))]
59/// Reports that compilation is unavailable because the `compiler` feature is disabled.
60///
61/// Consumers built without the compiler can deserialize and [`validate`] a
62/// document supplied by another trusted boundary instead.
63///
64/// # Errors
65///
66/// Always returns a diagnostic explaining that the compiler feature is disabled.
67pub fn compile(_: &str) -> Result<SceneDocument, Diagnostic> {
68 Err(Diagnostic::plain("the compiler feature is disabled"))
69}
70#[cfg(test)]
71mod tests;