pub struct Document { /* private fields */ }Expand description
A Codex document.
Document provides a high-level interface for working with Codex documents,
abstracting away the underlying archive structure.
Implementations§
Source§impl Document
impl Document
Sourcepub fn academic_numbering(&self) -> Option<&NumberingConfig>
pub fn academic_numbering(&self) -> Option<&NumberingConfig>
Get the academic numbering, if present.
Sourcepub fn academic_numbering_mut(&mut self) -> Result<Option<&mut NumberingConfig>>
pub fn academic_numbering_mut(&mut self) -> Result<Option<&mut NumberingConfig>>
Get a mutable reference to the academic numbering.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn has_academic_numbering(&self) -> bool
pub fn has_academic_numbering(&self) -> bool
Check if the document has academic numbering.
Sourcepub fn set_academic_numbering(&mut self, value: NumberingConfig) -> Result<()>
pub fn set_academic_numbering(&mut self, value: NumberingConfig) -> Result<()>
Sourcepub fn clear_academic_numbering(&mut self) -> Result<()>
pub fn clear_academic_numbering(&mut self) -> Result<()>
Sourcepub fn comments(&self) -> Option<&CommentThread>
pub fn comments(&self) -> Option<&CommentThread>
Get the comments, if present.
Sourcepub fn comments_mut(&mut self) -> Result<Option<&mut CommentThread>>
pub fn comments_mut(&mut self) -> Result<Option<&mut CommentThread>>
Get a mutable reference to the comments.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn has_comments(&self) -> bool
pub fn has_comments(&self) -> bool
Check if the document has comments.
Sourcepub fn set_comments(&mut self, value: CommentThread) -> Result<()>
pub fn set_comments(&mut self, value: CommentThread) -> Result<()>
Sourcepub fn clear_comments(&mut self) -> Result<()>
pub fn clear_comments(&mut self) -> Result<()>
Sourcepub fn phantom_clusters(&self) -> Option<&PhantomClusters>
pub fn phantom_clusters(&self) -> Option<&PhantomClusters>
Get the phantom clusters, if present.
Sourcepub fn phantom_clusters_mut(&mut self) -> Result<Option<&mut PhantomClusters>>
pub fn phantom_clusters_mut(&mut self) -> Result<Option<&mut PhantomClusters>>
Get a mutable reference to the phantom clusters.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn has_phantom_clusters(&self) -> bool
pub fn has_phantom_clusters(&self) -> bool
Check if the document has phantom clusters.
Sourcepub fn set_phantom_clusters(&mut self, value: PhantomClusters) -> Result<()>
pub fn set_phantom_clusters(&mut self, value: PhantomClusters) -> Result<()>
Sourcepub fn clear_phantom_clusters(&mut self) -> Result<()>
pub fn clear_phantom_clusters(&mut self) -> Result<()>
Sourcepub fn form_data_mut(&mut self) -> Result<Option<&mut FormData>>
pub fn form_data_mut(&mut self) -> Result<Option<&mut FormData>>
Get a mutable reference to the form data.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn has_form_data(&self) -> bool
pub fn has_form_data(&self) -> bool
Check if the document has form data.
Sourcepub fn set_form_data(&mut self, value: FormData) -> Result<()>
pub fn set_form_data(&mut self, value: FormData) -> Result<()>
Sourcepub fn clear_form_data(&mut self) -> Result<()>
pub fn clear_form_data(&mut self) -> Result<()>
Sourcepub fn bibliography(&self) -> Option<&Bibliography>
pub fn bibliography(&self) -> Option<&Bibliography>
Get the bibliography, if present.
Sourcepub fn bibliography_mut(&mut self) -> Result<Option<&mut Bibliography>>
pub fn bibliography_mut(&mut self) -> Result<Option<&mut Bibliography>>
Get a mutable reference to the bibliography.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn has_bibliography(&self) -> bool
pub fn has_bibliography(&self) -> bool
Check if the document has bibliography.
Sourcepub fn set_bibliography(&mut self, value: Bibliography) -> Result<()>
pub fn set_bibliography(&mut self, value: Bibliography) -> Result<()>
Sourcepub fn clear_bibliography(&mut self) -> Result<()>
pub fn clear_bibliography(&mut self) -> Result<()>
Sourcepub fn jsonld_metadata(&self) -> Option<&JsonLdMetadata>
pub fn jsonld_metadata(&self) -> Option<&JsonLdMetadata>
Get the JSON-LD metadata, if present.
Sourcepub fn jsonld_metadata_mut(&mut self) -> Result<Option<&mut JsonLdMetadata>>
pub fn jsonld_metadata_mut(&mut self) -> Result<Option<&mut JsonLdMetadata>>
Get a mutable reference to the JSON-LD metadata.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn has_jsonld_metadata(&self) -> bool
pub fn has_jsonld_metadata(&self) -> bool
Check if the document has JSON-LD metadata.
Sourcepub fn set_jsonld_metadata(&mut self, value: JsonLdMetadata) -> Result<()>
pub fn set_jsonld_metadata(&mut self, value: JsonLdMetadata) -> Result<()>
Sourcepub fn clear_jsonld_metadata(&mut self) -> Result<()>
pub fn clear_jsonld_metadata(&mut self) -> Result<()>
Source§impl Document
impl Document
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open a document from a file path.
§Errors
Returns an error if:
- The file cannot be opened
- The archive is invalid
- Required files are missing or malformed
Sourcepub fn open_from_reader<R: Read + Seek>(reader: R) -> Result<Self>
pub fn open_from_reader<R: Read + Seek>(reader: R) -> Result<Self>
Open a document from any Read + Seek source.
§Errors
Returns an error if:
- The source is not a valid Codex archive
- Required files are missing or malformed
Sourcepub fn from_bytes(data: Vec<u8>) -> Result<Self>
pub fn from_bytes(data: Vec<u8>) -> Result<Self>
Source§impl Document
impl Document
Sourcepub fn block_index(&self) -> Result<BlockIndex>
pub fn block_index(&self) -> Result<BlockIndex>
Generate a block index for this document.
The block index contains hashes for all content blocks and the Merkle root. This is used for generating proofs and verifying content integrity.
§Errors
Returns an error if the content has no blocks.
Sourcepub fn prove_block(&self, block_index: usize) -> Result<BlockProof>
pub fn prove_block(&self, block_index: usize) -> Result<BlockProof>
Generate a Merkle proof for a specific block by index.
The proof can be used to verify that a block is part of this document without revealing the entire document content.
§Arguments
block_index- The zero-based index of the block to prove
§Errors
Returns an error if:
- The content has no blocks
- The block index is out of bounds
Sourcepub fn prove_block_by_id(&self, block_id: &str) -> Result<BlockProof>
pub fn prove_block_by_id(&self, block_id: &str) -> Result<BlockProof>
Sourcepub fn verify_proof(&self, proof: &BlockProof, block_hash: &DocumentId) -> bool
pub fn verify_proof(&self, proof: &BlockProof, block_hash: &DocumentId) -> bool
Sourcepub fn merkle_root(&self) -> Result<DocumentId>
pub fn merkle_root(&self) -> Result<DocumentId>
Get the Merkle root hash for this document’s content.
§Errors
Returns an error if the content has no blocks.
Sourcepub fn provenance_record(&self) -> Result<ProvenanceRecord>
pub fn provenance_record(&self) -> Result<ProvenanceRecord>
Create a provenance record for this document.
§Errors
Returns an error if computing the document ID or Merkle root fails.
Source§impl Document
impl Document
Sourcepub fn signature_file(&self) -> Option<&SignatureFile>
Available on crate feature signatures only.
pub fn signature_file(&self) -> Option<&SignatureFile>
signatures only.Get a reference to the signature file, if present.
Sourcepub fn signatures(&self) -> &[Signature]
Available on crate feature signatures only.
pub fn signatures(&self) -> &[Signature]
signatures only.Get the signatures from the document.
Sourcepub fn add_signature(&mut self, signature: Signature) -> Result<()>
Available on crate feature signatures only.
pub fn add_signature(&mut self, signature: Signature) -> Result<()>
signatures only.Add a signature to the document.
This adds the signature to the document’s signature file. If no signature file exists, one will be created. The document ID in the signature file will be updated to match the current computed document ID.
§Errors
Returns an error if the document ID cannot be computed.
Sourcepub fn has_signatures(&self) -> bool
Available on crate feature signatures only.
pub fn has_signatures(&self) -> bool
signatures only.Check if the document has any signatures.
Sourcepub fn encryption_metadata(&self) -> Option<&EncryptionMetadata>
Available on crate feature encryption only.
pub fn encryption_metadata(&self) -> Option<&EncryptionMetadata>
encryption only.Get a reference to the encryption metadata, if present.
Sourcepub fn is_encrypted(&self) -> bool
Available on crate feature encryption only.
pub fn is_encrypted(&self) -> bool
encryption only.Check if the document has encryption metadata.
Sourcepub fn set_encryption(&mut self, metadata: EncryptionMetadata) -> Result<()>
Available on crate feature encryption only.
pub fn set_encryption(&mut self, metadata: EncryptionMetadata) -> Result<()>
encryption only.Set encryption metadata for this document.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn clear_encryption(&mut self) -> Result<()>
Available on crate feature encryption only.
pub fn clear_encryption(&mut self) -> Result<()>
encryption only.Remove encryption metadata from this document.
§Errors
Returns an error if the document is in an immutable state.
Source§impl Document
impl Document
Sourcepub fn submit_for_review(&mut self) -> Result<()>
pub fn submit_for_review(&mut self) -> Result<()>
Submit the document for review.
Transitions from draft to review state. This computes the document ID
and stores it in the manifest.
§Errors
Returns an error if:
- The document is not in draft state
- Computing the document ID fails
Sourcepub fn freeze(&mut self) -> Result<()>
pub fn freeze(&mut self) -> Result<()>
Freeze the document.
Transitions from review to frozen state. This requires:
- At least one signature
- Lineage information (parent reference or explicit root)
- At least one precise layout (for visual reproduction)
§Errors
Returns an error if:
- The document is not in review state
- No signatures are present
- No lineage is set
- No precise layout is present
Sourcepub fn publish(&mut self) -> Result<()>
pub fn publish(&mut self) -> Result<()>
Publish the document.
Transitions from frozen to published state.
§Errors
Returns an error if the document is not in frozen state.
Sourcepub fn revert_to_draft(&mut self) -> Result<()>
pub fn revert_to_draft(&mut self) -> Result<()>
Revert the document to draft state.
Transitions from review back to draft state. This is only allowed
if the document has no signatures (to prevent removing signed content).
§Errors
Returns an error if:
- The document is not in review state
- The document has signatures
Sourcepub fn fork(&self) -> Result<Document>
pub fn fork(&self) -> Result<Document>
Fork the document to create a new draft with lineage.
Creates a new document in draft state that references this document as its parent in the lineage chain. The forked document:
- Has a new (pending) document ID
- Is in draft state
- Has lineage pointing to this document with ancestor chain
- Has incremented version number and depth
- Has no signatures
§Errors
Returns an error if computing the document ID fails.
Sourcepub fn set_lineage(
&mut self,
parent: Option<DocumentId>,
version: u32,
note: Option<String>,
) -> Result<()>
pub fn set_lineage( &mut self, parent: Option<DocumentId>, version: u32, note: Option<String>, ) -> Result<()>
Set lineage information for this document.
This is used to establish lineage before freezing a document.
For the first version of a document, call with None as parent
to create a root lineage entry.
§Errors
Returns an error if the document is in an immutable state.
Source§impl Document
impl Document
Sourcepub fn compute_id(&self) -> Result<DocumentId>
pub fn compute_id(&self) -> Result<DocumentId>
Compute the document ID from content and identity metadata.
Per spec §06 §4.1, the document ID is computed by hashing the canonicalized semantic identity of the document. This includes:
- Content blocks (the document’s structural content)
- Identity metadata: title, creator, subject, description, language
The hash explicitly excludes presentation layers, signatures, phantom data, form data, and collaboration data — these are non-identity concerns with their own integrity mechanisms.
§Errors
Returns an error if canonicalization fails.
Sourcepub fn verify(&self) -> Result<VerificationReport>
pub fn verify(&self) -> Result<VerificationReport>
Verify the document integrity.
This checks:
- Content hash matches manifest
- Document ID is valid (if not pending)
§Errors
Returns an error if verification fails.
Sourcepub fn validate_extensions(&self) -> ExtensionValidationReport
pub fn validate_extensions(&self) -> ExtensionValidationReport
Validate extension declarations.
This checks that all extension namespaces used in the document’s content (blocks and marks) are declared in the manifest’s extensions list.
§Returns
An ExtensionValidationReport containing:
- List of used extension namespaces
- List of declared extension namespaces
- List of undeclared (used but not declared) namespaces
- Warnings for any issues found
Source§impl Document
impl Document
Sourcepub fn builder() -> DocumentBuilder
pub fn builder() -> DocumentBuilder
Create a new document builder.
Sourcepub fn content_mut(&mut self) -> Result<&mut Content>
pub fn content_mut(&mut self) -> Result<&mut Content>
Get a mutable reference to the content.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn dublin_core(&self) -> &DublinCore
pub fn dublin_core(&self) -> &DublinCore
Get a reference to the Dublin Core metadata.
Sourcepub fn dublin_core_mut(&mut self) -> Result<&mut DublinCore>
pub fn dublin_core_mut(&mut self) -> Result<&mut DublinCore>
Get a mutable reference to the Dublin Core metadata.
§Errors
Returns an error if the document is in an immutable state.
Sourcepub fn state(&self) -> DocumentState
pub fn state(&self) -> DocumentState
Get the document state.
Sourcepub fn id(&self) -> &DocumentId
pub fn id(&self) -> &DocumentId
Get the document ID.
Sourcepub fn hash_algorithm(&self) -> HashAlgorithm
pub fn hash_algorithm(&self) -> HashAlgorithm
Get the hash algorithm used.
Sourcepub fn manifest_mut(&mut self) -> &mut Manifest
pub fn manifest_mut(&mut self) -> &mut Manifest
Get a mutable reference to the manifest for advanced modifications.
Use with caution - this bypasses state machine validation.