Skip to main content

Document

Struct Document 

Source
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: Meta

Metadata.

§settings: Settings

Settings.

§extra: BTreeMap<String, Value>

Unknown top-level fields preserved on save.

Implementations§

Source§

impl Document

Source

pub fn canonical_value(&self) -> Result<Value, DocError>

Canonical JSON value.

Source

pub fn canonical_json(&self) -> Result<String, DocError>

Canonical JSON string (compact).

Source

pub fn content_hash(&self) -> Result<String, DocError>

Content hash of the canonical form, as 16 hex digits.

Source

pub fn semantic_eq(&self, other: &Self) -> bool

Semantic equality (canonical forms equal).

Source§

impl Document

Source

pub fn copy(&self, ids: &[EntityId]) -> Clipboard

Copy entities (and the constraints/groups fully inside the selection).

Source

pub fn paste( &mut self, clip: &Clipboard, offset: Vector, fallback_layer: LayerId, ) -> PasteReport

Paste clipboard content with new IDs, translated by offset. Entities whose layer does not exist here are placed on fallback_layer.

Source§

impl Document

Source

pub fn new() -> Self

Empty document with one default layer.

Source

pub fn alloc_id(&mut self) -> u64

Allocate a fresh ID (shared by all object kinds).

Source

pub const fn next_id(&self) -> u64

Next ID that will be allocated.

Source

pub fn reserve_id(&mut self, id: u64)

Raise the allocator so that id is never handed out again.

Source

pub fn entity_count(&self) -> usize

Number of entities.

Source

pub fn entity(&self, id: EntityId) -> Option<&Entity>

Entity by ID.

Source

pub fn entity_mut(&mut self, id: EntityId) -> Option<&mut Entity>

Mutable entity by ID (engine use; callers must re-validate).

Source

pub fn entities(&self) -> impl Iterator<Item = &Entity>

Entities in draw order.

Source

pub fn order(&self) -> &[EntityId]

Draw order.

Source

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).

Source

pub fn insert_entity_at(&mut self, e: Entity, index: usize)

Insert an entity at a draw-order index.

Source

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.

Source

pub fn reorder(&mut self, id: EntityId, index: usize) -> Result<(), DocError>

Move an entity to a draw-order index. IDs never change.

Source

pub fn order_index(&self, id: EntityId) -> Option<usize>

Draw-order index of an entity.

Source

pub fn layers(&self) -> &[Layer]

Layers in display order.

Source

pub fn layer(&self, id: LayerId) -> Option<&Layer>

Layer by ID.

Source

pub fn layer_mut(&mut self, id: LayerId) -> Option<&mut Layer>

Mutable layer by ID.

Source

pub fn upsert_layer(&mut self, l: Layer)

Insert or replace a layer (appended when new).

Source

pub fn set_layers(&mut self, layers: Vec<Layer>)

Replace the whole layer list (used by undo/redo).

Source

pub fn insert_layer_at(&mut self, l: Layer, index: usize)

Insert a layer at an index.

Source

pub fn remove_layer(&mut self, id: LayerId) -> Result<(Layer, usize), DocError>

Remove a layer. Fails while entities still use it.

Source

pub fn groups(&self) -> impl Iterator<Item = &Group>

Groups.

Source

pub fn group(&self, id: GroupId) -> Option<&Group>

Group by ID.

Source

pub fn upsert_group(&mut self, g: Group)

Insert or replace a group.

Source

pub fn remove_group(&mut self, id: GroupId) -> Option<Group>

Remove a group (members stay in the document).

Source

pub fn group_of(&self, id: EntityId) -> Option<GroupId>

Group that directly contains an entity.

Source

pub fn constraints(&self) -> impl Iterator<Item = &Constraint>

Constraints.

Source

pub fn constraint_count(&self) -> usize

Number of constraints.

Source

pub fn constraint(&self, id: ConstraintId) -> Option<&Constraint>

Constraint by ID.

Source

pub fn upsert_constraint(&mut self, c: Constraint)

Insert or replace a constraint.

Source

pub fn remove_constraint(&mut self, id: ConstraintId) -> Option<Constraint>

Remove a constraint.

Source

pub fn dependents(&self, id: EntityId) -> Dependents

Everything that references id (O(n); the engine keeps an index).

Source

pub fn id_in_use(&self, raw: u64) -> bool

Whether any ID of any kind equals raw.

Source§

impl Document

Source

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.

Source

pub fn from_json_slice( bytes: &[u8], limits: &Limits, ) -> Result<(Self, Vec<MigrationNote>), DocError>

Document::from_json_str on UTF-8 bytes.

Source

pub fn from_json_value( v: Value, limits: &Limits, ) -> Result<(Self, Vec<MigrationNote>), DocError>

Migrate and validate a parsed JSON value.

Source

pub fn to_json_string(&self) -> Result<String, DocError>

Serialize to pretty JSON.

Source§

impl Document

Source

pub fn validate(&self) -> Result<(), DocError>

First invariant violation, if any.

Source

pub fn validate_all(&self, limits: &Limits) -> Vec<DocError>

All invariant violations (bounded to the first 1000).

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Document

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Document

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Document

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Document

Source§

fn eq(&self, other: &Document) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Document

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Document

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.