pub struct DocumentComments(/* private fields */);Expand description
Every comment thread supplied to one export, keyed by DocumentComment::uid.
A BTreeMap, not a HashMap, for the same reason super::image_options::ExportImages
is one: two exports of the same document must be byte-comparable, and a randomised
iteration order would quietly break that. Keying by uid rather than storing a bare Vec
also makes “does this document already carry a thread with this id” an O(log n) lookup
instead of a linear scan — relevant because a caller re-exporting after an edit typically
hands over its whole current comment set again, not just what changed since last time.
Iteration order is uid order, which is not the order a writer needs to open and close
ranges in as it walks the document front to back — use
in_document_order for that.
Implementations§
Source§impl DocumentComments
impl DocumentComments
pub fn new() -> Self
Sourcepub fn insert(&mut self, comment: DocumentComment) -> &mut Self
pub fn insert(&mut self, comment: DocumentComment) -> &mut Self
Register a comment, keyed by its own uid. A second insert under the same uid
replaces the first — the caller is expected to hand over its current state on every
export, not maintain an append-only log through this type.
pub fn get(&self, uid: &str) -> Option<&DocumentComment>
pub fn iter(&self) -> impl Iterator<Item = &DocumentComment>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub fn in_document_order(&self) -> Vec<&DocumentComment>
pub fn in_document_order(&self) -> Vec<&DocumentComment>
Every comment, sorted by (start, end, uid) — the order a writer walking the document
text front-to-back needs to open and close ranges in. uid breaks an exact
(start, end) tie deterministically (two threads anchored to the identical span)
rather than leaving it to whatever order the BTreeMap’s own key (uid again, but
unsorted by position) happened to produce.
Trait Implementations§
Source§impl Clone for DocumentComments
impl Clone for DocumentComments
Source§fn clone(&self) -> DocumentComments
fn clone(&self) -> DocumentComments
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more