Skip to main content

Normalized

Struct Normalized 

Source
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

Source

pub fn empty() -> Normalized

Content::empty, which is already canonical.

Source

pub fn into_content(self) -> Content

Source§

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.

Source

pub fn apply_text_delta(&mut self, delta: &Delta) -> Result<(), ApplyError>

Source

pub fn apply_mark_ops(&mut self, ops: &[MarkOp]) -> Result<(), ApplyError>

Source

pub fn apply_island_ops(&mut self, ops: &[IslandOp]) -> Result<(), ApplyError>

Source

pub fn apply_line_ops(&mut self, ops: &[LineOp]) -> Result<(), ApplyError>

Source

pub fn apply_field_change( &mut self, bundle: &ChangeBundle, ) -> Result<(), ApplyError>

Source§

impl Normalized

Source

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>§

Source

pub fn len_usv(&self) -> Usv

Total length in USV.

Source

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.

Source

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.

Source

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.

Source

pub fn segment_count(&self) -> usize

Number of \n-separated segments: the required lines.len().

Source

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.

Source

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

Source§

fn clone(&self) -> Normalized

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 Normalized

Source§

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

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

impl Deref for Normalized

Source§

type Target = Content

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Content

Dereferences the value.
Source§

impl From<Content> for Normalized

Source§

fn from(rt: Content) -> Normalized

Converts to this type from the input type.
Source§

impl PartialEq for Normalized

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Normalized

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.