Skip to main content

Crate cp_ast_json

Crate cp_ast_json 

Source
Expand description

Lossless JSON serialization for cp-ast-core AST documents.

Provides full-snapshot JSON roundtrip that preserves arena structure, tombstones, IDs, counters, and ordering through Rust → JS → Rust cycles.

Use serialize_ast and deserialize_ast for complete documents, or serialize_ast_compact when byte size matters. Editor integrations can serialize actions with serialize_action / deserialize_action and serialize UI projections with serialize_projection.

§Example

use cp_ast_core::operation::AstEngine;
use cp_ast_json::{deserialize_ast, serialize_ast};

let engine = AstEngine::new();
let json = serialize_ast(&engine).expect("serialize");
let restored = deserialize_ast(&json).expect("deserialize");

assert_eq!(restored.structure.root(), engine.structure.root());

§Schema Notes

IDs are encoded as decimal strings so JavaScript callers do not lose integer precision. The top-level JSON document is versioned with dto::CURRENT_SCHEMA_VERSION.

Re-exports§

pub use dto::AstDocumentEnvelope;
pub use error::ConversionError;
pub use share_state::decode_share_state_json;
pub use share_state::deserialize_share_state;
pub use share_state::encode_share_state_json;

Modules§

dto
DTO types that define the stable JSON schema. Data Transfer Objects for lossless AST JSON serialization.
error
Error type returned by JSON conversion functions.
share_state
Compact share-link encoding helpers. Share-link state codec used by the web UI and companion CLIs.

Functions§

deserialize_action
Deserialize an Action from a JSON string.
deserialize_ast
Deserialize an AstEngine from a JSON string.
serialize_action
Serialize an Action to a JSON string.
serialize_ast
Serialize an AstEngine to a JSON string.
serialize_ast_compact
Serialize an AstEngine to a compact JSON string.
serialize_projection
Serialize a FullProjection to a JSON string.