# Document

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-designer-core/struct-document/

**struct** · [`ferroui-designer-core`](/docs/0.5.0/api/ferroui-designer-core/) · v0.5.0

```rust
struct Document
```

An owned source buffer with a last-valid syntax snapshot and bounded history.
Runtime acceptance is deliberately separate: the host may keep an older live
tree when compilation fails, while authored and syntactically valid XAML stays
available for correction.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L178)

## Members

- [`new`](#function-new)
- [`source`](#function-source)
- [`valid_source`](#function-valid_source)
- [`revision`](#function-revision)
- [`snapshot_without_history`](#function-snapshot_without_history)
- [`advance_revision_to`](#function-advance_revision_to)
- [`ast`](#function-ast)
- [`ast_snapshot`](#function-ast_snapshot)
- [`diagnostics`](#function-diagnostics)
- [`is_valid`](#function-is_valid)
- [`is_dirty`](#function-is_dirty)
- [`mark_saved`](#function-mark_saved)
- [`mark_saved_snapshot`](#function-mark_saved_snapshot)
- [`can_undo`](#function-can_undo)
- [`can_redo`](#function-can_redo)
- [`undo_label`](#function-undo_label)
- [`redo_label`](#function-redo_label)
- [`set_history_limit`](#function-set_history_limit)
- [`apply`](#function-apply)
- [`apply_at`](#function-apply_at)
- [`transact`](#function-transact)
- [`apply_text_patches`](#function-apply_text_patches)
- [`update_source`](#function-update_source)
- [`try_update_source`](#function-try_update_source)
- [`update_source_at`](#function-update_source_at)
- [`undo`](#function-undo)
- [`redo`](#function-redo)

<a id="function-new"></a>

### new

```rust
fn new(source: impl Into<String>) -> Result<Self, DesignerError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L188)

<a id="function-source"></a>

### source

```rust
fn source(self: &Self) -> &str
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L209)

<a id="function-valid_source"></a>

### valid_source

```rust
fn valid_source(self: &Self) -> &str
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L212)

<a id="function-revision"></a>

### revision

```rust
fn revision(self: &Self) -> u64
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L215)

<a id="function-snapshot_without_history"></a>

### snapshot_without_history

```rust
fn snapshot_without_history(self: &Self) -> Self
```

Capture the exact current buffer, accepted syntax identity and saved state
without copying its undo/redo history. Preview hosts can retain this cheap
snapshot without retaining every authoring transaction. Subsequent edits
to either document are independent; new edits use the same history limit.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L222)

<a id="function-advance_revision_to"></a>

### advance_revision_to

```rust
fn advance_revision_to(self: &mut Self, minimum: u64) -> Result<(), DesignerError>
```

Rebase a restored tab onto its host's monotonic revision sequence without altering
source, stable node IDs, dirty state or history. Reserve the next revision for editing.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L235)

<a id="function-ast"></a>

### ast

```rust
fn ast(self: &Self) -> &Ast
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L244)

<a id="function-ast_snapshot"></a>

### ast_snapshot

```rust
fn ast_snapshot(self: &Self) -> Arc<Ast>
```

Share the exact immutable syntax snapshot without copying its nodes.
A gesture can retain this handle together with a revision to reject a
command prepared for a different document, even if its local IDs match.
Invalid source returns the last-valid syntax, like `ast()`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L251)

<a id="function-diagnostics"></a>

### diagnostics

```rust
fn diagnostics(self: &Self) -> &[Diagnostic]
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L254)

<a id="function-is_valid"></a>

### is_valid

```rust
fn is_valid(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L257)

<a id="function-is_dirty"></a>

### is_dirty

```rust
fn is_dirty(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L260)

<a id="function-mark_saved"></a>

### mark_saved

```rust
fn mark_saved(self: &mut Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L263)

<a id="function-mark_saved_snapshot"></a>

### mark_saved_snapshot

```rust
fn mark_saved_snapshot(self: &mut Self, source: impl Into<String>)
```

Acknowledge the exact snapshot written by an asynchronous storage provider. The
current buffer may already contain newer edits; revision and history are unchanged.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L268)

<a id="function-can_undo"></a>

### can_undo

```rust
fn can_undo(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L271)

<a id="function-can_redo"></a>

### can_redo

```rust
fn can_redo(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L274)

<a id="function-undo_label"></a>

### undo_label

```rust
fn undo_label(self: &Self) -> Option<&str>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L277)

<a id="function-redo_label"></a>

### redo_label

```rust
fn redo_label(self: &Self) -> Option<&str>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L280)

<a id="function-set_history_limit"></a>

### set_history_limit

```rust
fn set_history_limit(self: &mut Self, limit: usize)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L283)

<a id="function-apply"></a>

### apply

```rust
fn apply(self: &mut Self, label: impl Into<String>, edits: Vec<Edit>) -> Result<ChangeSet, DesignerError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L288)

<a id="function-apply_at"></a>

### apply_at

```rust
fn apply_at(self: &mut Self, expected_revision: u64, label: impl Into<String>, edits: Vec<Edit>) -> Result<ChangeSet, DesignerError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L295)

<a id="function-transact"></a>

### transact

```rust
fn transact(self: &mut Self, transaction: Transaction) -> Result<ChangeSet, DesignerError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L303)

<a id="function-apply_text_patches"></a>

### apply_text_patches

```rust
fn apply_text_patches(self: &mut Self, expected_revision: u64, label: impl Into<String>, patches: Vec<TextPatch>) -> Result<ChangeSet, DesignerError>
```

Apply disjoint editor patches atomically. All spans refer to the current
authored source; UTF-8 boundaries and overlap are checked before mutation.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L321)

<a id="function-update_source"></a>

### update_source

```rust
fn update_source(self: &mut Self, label: impl Into<String>, source: impl Into<String>) -> SourceUpdate
```

Source editors may temporarily contain invalid XML. The raw buffer and
diagnostics enter history, while the AST/preview source remain the last
valid snapshot. A subsequent valid source update reconciles node IDs.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L345)

<a id="function-try_update_source"></a>

### try_update_source

```rust
fn try_update_source(self: &mut Self, label: impl Into<String>, source: impl Into<String>) -> Result<SourceUpdate, DesignerError>
```

Fallible source editing for hosts that must distinguish a rejected write
from an accepted but temporarily invalid XML buffer. Revision exhaustion
cannot alter source, node identity, history or saved-state tracking.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L363)

<a id="function-update_source_at"></a>

### update_source_at

```rust
fn update_source_at(self: &mut Self, expected_revision: u64, label: impl Into<String>, source: impl Into<String>) -> Result<SourceUpdate, DesignerError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L396)

<a id="function-undo"></a>

### undo

```rust
fn undo(self: &mut Self) -> Result<ChangeSet, DesignerError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L405)

<a id="function-redo"></a>

### redo

```rust
fn redo(self: &mut Self) -> Result<ChangeSet, DesignerError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Designer.Core/document.rs#L425)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `Clone`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
