Skip to main content

DocumentMark

Struct DocumentMark 

Source
pub struct DocumentMark {
    pub start: u32,
    pub end: u32,
    pub name: String,
    pub ordinal: u32,
}
Expand description

One named position or range in the document’s addressable character space.

Fields§

§start: u32

[start, end) in the document’s addressable character space — the same space DocumentComment::start uses, and the same one TextDocument::to_addressable_text() reports. start == end is a point mark.

§end: u32§name: String

The bookmark name, which is the whole message. See validate.

§ordinal: u32

Which of several marks sharing this exact range comes first.

Zero for every mark that does not share its range with another, which is almost all of them, so it can be ignored by any caller that never emits two.

It exists because ties have to break the same way on both payloads. A comment and the mark carrying its identity are two objects the writers sort independently: DocumentComments breaks a tie on the comment’s uid, and this on the mark’s name. Where a name is derived from a uid by hashing — which is what a 40-character bookmark limit forces — the two orders are uncorrelated, so a document with two comments on the identical range can emit the annotations in one order and their marks in the other. A reader matching them by position then hands each comment the other’s identity, and the editor’s remark comes home on the wrong thread.

The producer knows the intended order and nothing else can recover it, so the producer says: set this from the same sequence the comments are built in.

#[serde(default)] because this field was added after the type shipped: a payload serialized before it exists has no ordinal, and reading it back must give 0 rather than fail. The default is also the correct answer for such a payload — it was written by a producer that stated no order.

Implementations§

Source§

impl DocumentMark

Source

pub fn point(at: u32, name: impl Into<String>) -> DocumentMark

A point mark at at.

Source

pub fn range(start: u32, end: u32, name: impl Into<String>) -> DocumentMark

A range mark over [start, end).

Source

pub fn with_ordinal(self, ordinal: u32) -> DocumentMark

This mark, ordered ahead of or behind others sharing its exact range.

See ordinal — required only when two marks can span the same characters, which for a host carrying comment identity means two comments on one paragraph.

Source

pub fn is_point(&self) -> bool

True when this mark names a position rather than a span.

Source

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

Check the name against the stricter of the two formats’ rules, and the range against itself.

Returns a description of the problem rather than a bool, because every caller of this wants to say what was wrong: these names are minted by the host from its own data, so a rejected one is a programming error and deserves to be reported as one — not silently dropped, which would leave an export that looks complete and cannot be read back.

Trait Implementations§

Source§

impl Clone for DocumentMark

Source§

fn clone(&self) -> DocumentMark

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 DocumentMark

Source§

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

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

impl Default for DocumentMark

Source§

fn default() -> DocumentMark

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

impl<'de> Deserialize<'de> for DocumentMark

Source§

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

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

impl Eq for DocumentMark

Source§

impl PartialEq for DocumentMark

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for DocumentMark

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl StructuralPartialEq for DocumentMark

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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.