pub struct Document {
pub meta: Meta,
pub settings: Settings,
pub extra: BTreeMap<String, Value>,
/* private fields */
}Expand description
A Dotloom document: the single editable source of truth (owned by the engine).
Entities are kept in a map keyed by stable ID plus a separate draw order, so
reordering never changes identity. IDs for every object kind come from one
monotonically increasing allocator (next_id) and are never reused.
Fields§
§meta: MetaMetadata.
settings: SettingsSettings.
extra: BTreeMap<String, Value>Unknown top-level fields preserved on save.
Implementations§
Source§impl Document
impl Document
Sourcepub fn canonical_value(&self) -> Result<Value, DocError>
pub fn canonical_value(&self) -> Result<Value, DocError>
Canonical JSON value.
Sourcepub fn canonical_json(&self) -> Result<String, DocError>
pub fn canonical_json(&self) -> Result<String, DocError>
Canonical JSON string (compact).
Sourcepub fn content_hash(&self) -> Result<String, DocError>
pub fn content_hash(&self) -> Result<String, DocError>
Content hash of the canonical form, as 16 hex digits.
Sourcepub fn semantic_eq(&self, other: &Self) -> bool
pub fn semantic_eq(&self, other: &Self) -> bool
Semantic equality (canonical forms equal).
Source§impl Document
impl Document
Source§impl Document
impl Document
Sourcepub fn reserve_id(&mut self, id: u64)
pub fn reserve_id(&mut self, id: u64)
Raise the allocator so that id is never handed out again.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Number of entities.
Sourcepub fn entity_mut(&mut self, id: EntityId) -> Option<&mut Entity>
pub fn entity_mut(&mut self, id: EntityId) -> Option<&mut Entity>
Mutable entity by ID (engine use; callers must re-validate).
Sourcepub fn insert_entity(&mut self, e: Entity)
pub fn insert_entity(&mut self, e: Entity)
Insert an entity at the top of the draw order (or replace one with the same ID in place).
Sourcepub fn insert_entity_at(&mut self, e: Entity, index: usize)
pub fn insert_entity_at(&mut self, e: Entity, index: usize)
Insert an entity at a draw-order index.
Sourcepub fn remove_entity(&mut self, id: EntityId) -> Option<(Entity, usize)>
pub fn remove_entity(&mut self, id: EntityId) -> Option<(Entity, usize)>
Remove an entity (does not touch constraints or references; see
Document::dependents). Returns the entity and its draw-order index.
Sourcepub fn reorder(&mut self, id: EntityId, index: usize) -> Result<(), DocError>
pub fn reorder(&mut self, id: EntityId, index: usize) -> Result<(), DocError>
Move an entity to a draw-order index. IDs never change.
Sourcepub fn order_index(&self, id: EntityId) -> Option<usize>
pub fn order_index(&self, id: EntityId) -> Option<usize>
Draw-order index of an entity.
Sourcepub fn upsert_layer(&mut self, l: Layer)
pub fn upsert_layer(&mut self, l: Layer)
Insert or replace a layer (appended when new).
Sourcepub fn set_layers(&mut self, layers: Vec<Layer>)
pub fn set_layers(&mut self, layers: Vec<Layer>)
Replace the whole layer list (used by undo/redo).
Sourcepub fn insert_layer_at(&mut self, l: Layer, index: usize)
pub fn insert_layer_at(&mut self, l: Layer, index: usize)
Insert a layer at an index.
Sourcepub fn remove_layer(&mut self, id: LayerId) -> Result<(Layer, usize), DocError>
pub fn remove_layer(&mut self, id: LayerId) -> Result<(Layer, usize), DocError>
Remove a layer. Fails while entities still use it.
Sourcepub fn upsert_group(&mut self, g: Group)
pub fn upsert_group(&mut self, g: Group)
Insert or replace a group.
Sourcepub fn remove_group(&mut self, id: GroupId) -> Option<Group>
pub fn remove_group(&mut self, id: GroupId) -> Option<Group>
Remove a group (members stay in the document).
Sourcepub fn group_of(&self, id: EntityId) -> Option<GroupId>
pub fn group_of(&self, id: EntityId) -> Option<GroupId>
Group that directly contains an entity.
Sourcepub fn constraints(&self) -> impl Iterator<Item = &Constraint>
pub fn constraints(&self) -> impl Iterator<Item = &Constraint>
Constraints.
Sourcepub fn constraint_count(&self) -> usize
pub fn constraint_count(&self) -> usize
Number of constraints.
Sourcepub fn constraint(&self, id: ConstraintId) -> Option<&Constraint>
pub fn constraint(&self, id: ConstraintId) -> Option<&Constraint>
Constraint by ID.
Sourcepub fn upsert_constraint(&mut self, c: Constraint)
pub fn upsert_constraint(&mut self, c: Constraint)
Insert or replace a constraint.
Sourcepub fn remove_constraint(&mut self, id: ConstraintId) -> Option<Constraint>
pub fn remove_constraint(&mut self, id: ConstraintId) -> Option<Constraint>
Remove a constraint.
Sourcepub fn dependents(&self, id: EntityId) -> Dependents
pub fn dependents(&self, id: EntityId) -> Dependents
Everything that references id (O(n); the engine keeps an index).
Source§impl Document
impl Document
Sourcepub fn from_json_str(
s: &str,
limits: &Limits,
) -> Result<(Self, Vec<MigrationNote>), DocError>
pub fn from_json_str( s: &str, limits: &Limits, ) -> Result<(Self, Vec<MigrationNote>), DocError>
Parse, migrate and validate a document from JSON text.
Documents of the current schema are deserialized directly; only older
schemas go through the JSON tree the migration steps work on (the tree costs
several times the document’s own memory: ~150 MB for 100 000 shapes). Nesting
depth stays bounded by serde_json’s recursion limit (128) on both paths.
Sourcepub fn from_json_slice(
bytes: &[u8],
limits: &Limits,
) -> Result<(Self, Vec<MigrationNote>), DocError>
pub fn from_json_slice( bytes: &[u8], limits: &Limits, ) -> Result<(Self, Vec<MigrationNote>), DocError>
Document::from_json_str on UTF-8 bytes.
Sourcepub fn from_json_value(
v: Value,
limits: &Limits,
) -> Result<(Self, Vec<MigrationNote>), DocError>
pub fn from_json_value( v: Value, limits: &Limits, ) -> Result<(Self, Vec<MigrationNote>), DocError>
Migrate and validate a parsed JSON value.
Sourcepub fn to_json_string(&self) -> Result<String, DocError>
pub fn to_json_string(&self) -> Result<String, DocError>
Serialize to pretty JSON.