pub struct Normalized(/* private fields */);Expand description
A Content that Content::normalize has run on: the precondition both
projections carry. Minted only by Content::into_normalized, which the
codecs decode through; a mutation that does not re-establish the invariant
takes into_content and mints again.
§Canonical, not valid
validate rejects a disjoint set: what normalization
cannot repair. Nothing it does brings a container path under
MAX_NESTING_DEPTH, so a token can hold a
content validate refuses, and the mint stays infallible on that split. The
codecs call validate after minting; a Rust embedder hand-building a
Content may not.
A projection taking a token may therefore assume only what the mint
establishes, and must be total over any token:
to_markdown walks containers on an explicit stack
rather than a frame per level, and emit_content checks the depth and
returns an error. An unguarded recursion aborts the process, which no
Result can catch.
Implementations§
Source§impl Normalized
impl Normalized
Sourcepub fn empty() -> Normalized
pub fn empty() -> Normalized
Content::empty, which is already canonical.
pub fn into_content(self) -> Content
Source§impl Normalized
The mutations that re-establish the invariant, forwarded.
impl Normalized
The mutations that re-establish the invariant, forwarded.
Each normalizes before it returns, on an error too: an op list that fails partway leaves its earlier ops applied. So the token states that the value is canonical, not that the edit landed.
Any other edit takes into_content.
pub fn apply_text_delta(&mut self, delta: &Delta) -> Result<(), ApplyError>
pub fn apply_mark_ops(&mut self, ops: &[MarkOp]) -> Result<(), ApplyError>
pub fn apply_island_ops(&mut self, ops: &[IslandOp]) -> Result<(), ApplyError>
pub fn apply_line_ops(&mut self, ops: &[LineOp]) -> Result<(), ApplyError>
pub fn apply_field_change( &mut self, bundle: &ChangeBundle, ) -> Result<(), ApplyError>
Source§impl Normalized
impl Normalized
Sourcepub fn to_canonical_json(&self) -> String
pub fn to_canonical_json(&self) -> String
Serialize to canonical JSON bytes. Every object key comes out in
ascending order at every depth, so the bytes do not depend on
serde_json’s preserve_order feature in the consumer’s crate graph.
On Normalized for the reason that token exists: canonical bytes need
canonical input, and the mint is where a caller’s mark/island order
settles.
Methods from Deref<Target = Content>§
Sourcepub fn is_inline(&self) -> bool
pub fn is_inline(&self) -> bool
Whether this content satisfies the richtext(inline) constraint: exactly
one Para line, sitting in no container, with no islands.
Content::empty is inline, so a blank inline field passes.
Sourcepub fn is_plain(&self) -> bool
pub fn is_plain(&self) -> bool
Whether this content satisfies the plaintext constraint: no marks, no
islands, and every line a plain Para sitting in no container.
continues is unconstrained. Content::empty is plain.
The distinguishing property of plaintext over richtext { marks: [] } is
the literal codec (crate::import::from_plaintext), not this
predicate.
Sourcepub fn is_blank(&self) -> bool
pub fn is_blank(&self) -> bool
Whether the text is empty or whitespace-only. An ISLAND_SLOT is not
whitespace, so an island-bearing content is never blank.
Sourcepub fn segment_count(&self) -> usize
pub fn segment_count(&self) -> usize
Number of \n-separated segments: the required lines.len().
Sourcepub fn validate(&self) -> Result<(), Invariant>
pub fn validate(&self) -> Result<(), Invariant>
What the mint cannot repair. Ok(()) on every content a codec or an
accepted op hands out; a hand-built one can fail it.
Sourcepub fn map_marks(&self, bundle: &ChangeBundle) -> Result<Vec<Mark>, ApplyError>
pub fn map_marks(&self, bundle: &ChangeBundle) -> Result<Vec<Mark>, ApplyError>
Where bundle’s text-moving channels leave the marks this content
already holds: the final-text coordinates ChangeBundle::mark_ops are
written in, under the rebase rule stated on ChangeBundle.
bundle.mark_ops are ignored, so an editor building them diffs its
intended marks against this instead of predicting the rebase. The answer
is normalized, as the store’s is: marks a text move
drops (out of range, zero-width formatting) are absent, and same-kind
runs a move left adjacent arrive already unioned. A bundle whose
mark_ops are empty therefore names the marks the field will hold.
Errors are apply_field_change’s on the same
ops, minus those only a mark op raises.
Trait Implementations§
Source§impl Clone for Normalized
impl Clone for Normalized
Source§fn clone(&self) -> Normalized
fn clone(&self) -> Normalized
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more