🎨 anchor.rs
This commit is contained in:
parent
acb29eb273
commit
2952f2c905
1 changed files with 31 additions and 21 deletions
|
@ -1,6 +1,4 @@
|
|||
use crate::Point;
|
||||
|
||||
use super::{Buffer, Content};
|
||||
use super::{Buffer, Content, Point};
|
||||
use anyhow::Result;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
|
@ -87,6 +85,14 @@ impl Anchor {
|
|||
}
|
||||
|
||||
impl<T> AnchorMap<T> {
|
||||
pub fn version(&self) -> &clock::Global {
|
||||
&self.version
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
pub fn offsets<'a>(
|
||||
&'a self,
|
||||
content: impl Into<Content<'a>> + 'a,
|
||||
|
@ -106,29 +112,41 @@ impl<T> AnchorMap<T> {
|
|||
.summaries_for_anchors(self)
|
||||
.map(move |(sum, value)| (sum.lines, value))
|
||||
}
|
||||
|
||||
pub fn version(&self) -> &clock::Global {
|
||||
&self.version
|
||||
}
|
||||
}
|
||||
|
||||
impl AnchorSet {
|
||||
pub fn version(&self) -> &clock::Global {
|
||||
&self.0.version
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
pub fn offsets<'a>(
|
||||
&'a self,
|
||||
content: impl Into<Content<'a>> + 'a,
|
||||
) -> impl Iterator<Item = usize> + 'a {
|
||||
self.0.offsets(content).map(move |(offset, _)| offset)
|
||||
self.0.offsets(content).map(|(offset, _)| offset)
|
||||
}
|
||||
|
||||
pub fn points<'a>(
|
||||
&'a self,
|
||||
content: impl Into<Content<'a>> + 'a,
|
||||
) -> impl Iterator<Item = Point> + 'a {
|
||||
self.0.points(content).map(move |(point, _)| point)
|
||||
self.0.points(content).map(|(point, _)| point)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AnchorRangeMap<T> {
|
||||
pub fn version(&self) -> &clock::Global {
|
||||
&self.version
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
pub fn from_raw(version: clock::Global, entries: Vec<(Range<(usize, Bias)>, T)>) -> Self {
|
||||
Self { version, entries }
|
||||
}
|
||||
|
@ -137,10 +155,6 @@ impl<T> AnchorRangeMap<T> {
|
|||
&self.entries
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
pub fn point_ranges<'a>(
|
||||
&'a self,
|
||||
content: impl Into<Content<'a>> + 'a,
|
||||
|
@ -160,10 +174,6 @@ impl<T> AnchorRangeMap<T> {
|
|||
.summaries_for_anchor_ranges(self)
|
||||
.map(move |(range, value)| ((range.start.bytes..range.end.bytes), value))
|
||||
}
|
||||
|
||||
pub fn version(&self) -> &clock::Global {
|
||||
&self.version
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PartialEq> PartialEq for AnchorRangeMap<T> {
|
||||
|
@ -200,6 +210,10 @@ impl AnchorRangeSet {
|
|||
self.0.len()
|
||||
}
|
||||
|
||||
pub fn version(&self) -> &clock::Global {
|
||||
self.0.version()
|
||||
}
|
||||
|
||||
pub fn offset_ranges<'a>(
|
||||
&'a self,
|
||||
content: impl Into<Content<'a>> + 'a,
|
||||
|
@ -213,10 +227,6 @@ impl AnchorRangeSet {
|
|||
) -> impl Iterator<Item = Range<Point>> + 'a {
|
||||
self.0.point_ranges(content).map(|(range, _)| range)
|
||||
}
|
||||
|
||||
pub fn version(&self) -> &clock::Global {
|
||||
self.0.version()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AnchorRangeExt {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue