Skip to main content

Crate gsim_py

Crate gsim_py 

Source
Expand description

PyO3 bindings for gsim-core.

§Interface design

Every function here is stateless and JSON-in/JSON-out: it takes Python str (JSON text), parses it with serde_json, calls straight into gsim-core, and returns Python str (JSON text) or raises a ValueError carrying the real Rust error’s Display message. There is no stateful Rust object (e.g. ModelBuilder) exposed across the FFI boundary — a caller builds a Model up incrementally by round-tripping its JSON through successive calls (new_model -> add_block -> connect -> … -> save_document). This matches gsim-core’s own internal philosophy of JSON as the interchange format everywhere, avoids needing GC/ lifetime integration for a wrapped Rust object living inside Python’s object model, and keeps this crate a thin wrapper rather than a second place schema/validation/layout logic could drift. crates/gsim-wasm exposes the same JSON contracts to JavaScript.

No function here reimplements schema, validation, or layout logic — see AGENTS.md’s “one implementation, thin bindings” rule. A couple of small additive helpers were added to gsim-core itself to support this thin-wrapper shape without duplicating shape definitions in this crate: Deserialize on document::NewBlockSpec/document::ConnectOptions, Serialize on contract::ValidationFailure, and Serialize/Deserialize on layout::Rect — see each item’s doc comment in gsim-core for why.