Skip to main content

cdx_core/
lib.rs

1//! # cdx-core
2//!
3//! Core library for reading, writing, and validating Codex Document Format (`.cdx`) files.
4//!
5//! ## Overview
6//!
7//! Codex is an open document format designed for semantic content, verifiable integrity,
8//! and machine readability. This library provides the foundational capabilities for working
9//! with Codex documents in Rust.
10//!
11//! ## Quick Start
12//!
13//! ```rust,ignore
14//! use cdx_core::{Document, DocumentState};
15//!
16//! // Open an existing document
17//! let doc = Document::open("example.cdx")?;
18//! println!("State: {:?}", doc.state());
19//!
20//! // Verify document integrity
21//! doc.verify()?;
22//! ```
23//!
24//! ## Features
25//!
26//! - `zstd` (default): Zstandard compression support
27//! - `wasm`: WASM compilation support
28
29#![cfg_attr(docsrs, feature(doc_cfg))]
30#![deny(missing_docs)]
31#![deny(unsafe_code)]
32#![warn(clippy::all)]
33#![warn(clippy::pedantic)]
34#![allow(clippy::module_name_repetitions)]
35
36pub mod anchor;
37pub mod archive;
38pub mod asset;
39pub mod content;
40mod document;
41mod error;
42pub mod extensions;
43mod hash;
44mod manifest;
45pub mod metadata;
46pub mod presentation;
47pub mod provenance;
48#[cfg(feature = "signatures")]
49#[cfg_attr(docsrs, doc(cfg(feature = "signatures")))]
50pub mod security;
51mod state;
52pub mod validation;
53
54pub use document::{Document, DocumentBuilder, ExtensionValidationReport, VerificationReport};
55pub use error::{Error, Result};
56pub use hash::{DocumentId, HashAlgorithm, Hasher};
57pub use manifest::{
58    AssetManifest, ContentRef, Extension, FileRef, Lineage, Manifest, Metadata, PresentationRef,
59    SecurityRef,
60};
61pub use state::DocumentState;
62
63/// Codex specification version implemented by this library.
64pub const SPEC_VERSION: &str = "0.1";
65
66/// Default file extension for Codex documents.
67pub const FILE_EXTENSION: &str = "cdx";
68
69/// MIME type for Codex documents (JSON format).
70pub const MIME_TYPE: &str = "application/vnd.codex+json";
71
72#[cfg(test)]
73mod tests {
74    use super::*;
75
76    #[test]
77    fn test_constants() {
78        assert_eq!(SPEC_VERSION, "0.1");
79        assert_eq!(FILE_EXTENSION, "cdx");
80        assert_eq!(MIME_TYPE, "application/vnd.codex+json");
81    }
82}