text_buffer/
position.rs

1use crate::metric::Metric;
2
3/// A position in the text buffer. This tracks both the bytes and characters.
4#[derive(Copy, Clone, PartialEq, Eq, Debug)]
5pub struct Position {
6    metric: Metric,
7}
8
9impl Position {
10    pub(crate) fn new(metric: Metric) -> Self {
11        Self { metric }
12    }
13
14    /// Return the number of characters before the current position.
15    #[must_use]
16    pub fn chars(&self) -> usize {
17        self.metric.chars
18    }
19
20    /// Return the number of bytes before the current position.
21    #[must_use]
22    pub fn bytes(&self) -> usize {
23        self.metric.bytes
24    }
25}