aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-17 07:07:56 +0200
committerMartin Fischer <martin@push-f.com>2023-08-19 11:40:58 +0200
commitbec70ad5c493cd85a4c972cf917f455ace1a88d0 (patch)
treea723cf29e1d8cc8dc119ae1af8b81e3a9654ee06 /src
parentc899f2f36df0371af776f21231ccdf0d30a2aaab (diff)
break!: rename GetPos trait to Position
More in line with RFC 344.[1] [1]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#gettersetter-apis
Diffstat (limited to 'src')
-rw-r--r--src/spans.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/spans.rs b/src/spans.rs
index 0a29eb2..89595aa 100644
--- a/src/spans.rs
+++ b/src/spans.rs
@@ -6,21 +6,21 @@
//! * one for `()` which acts as the no-op implementation for when you don't want to track spans
//! * one for [`Range<usize>`] for when you do want to track spans
//!
-//! To use the latter your reader however has to implement [`GetPos`].
+//! To use the latter your reader however has to implement [`Position`].
//! You can easily use any existing reader by wrapping it in the [`PosTrackingReader`] struct
-//! which implements the [`GetPos`] trait and takes care of tracking the current position.
+//! which implements the [`Position`] trait and takes care of tracking the current position.
use std::ops::Range;
use crate::reader::{IntoReader, Reader};
/// A trait to be implemented by readers that track their own position.
-pub trait GetPos {
+pub trait Position {
/// Returns the byte index of the current position.
- fn get_pos(&self) -> usize;
+ fn position(&self) -> usize;
}
-/// Wraps a [`Reader`] so that it implements [`GetPos`].
+/// Wraps a [`Reader`] so that it implements [`Position`].
pub struct PosTrackingReader<R> {
/// The wrapped reader.
reader: R,
@@ -29,7 +29,7 @@ pub struct PosTrackingReader<R> {
}
impl<R> PosTrackingReader<R> {
- /// Wraps the given [`Reader`] so that it implements [`GetPos`] with the position starting from 0.
+ /// Wraps the given [`Reader`] so that it implements [`Position`] with the position starting from 0.
pub fn new<'a>(into_reader: impl IntoReader<'a, Reader = R>) -> Self {
Self {
reader: into_reader.into_reader(),
@@ -38,8 +38,8 @@ impl<R> PosTrackingReader<R> {
}
}
-impl<R> GetPos for PosTrackingReader<R> {
- fn get_pos(&self) -> usize {
+impl<R> Position for PosTrackingReader<R> {
+ fn position(&self) -> usize {
self.position
}
}
@@ -64,13 +64,13 @@ impl<R> Span<R> for () {
fn push_str(&mut self, _str: &str) {}
}
-impl<P: GetPos> Span<P> for Range<usize> {
+impl<P: Position> Span<P> for Range<usize> {
fn from_reader(reader: &P) -> Self {
- reader.get_pos() - 1..reader.get_pos() - 1
+ reader.position() - 1..reader.position() - 1
}
fn from_reader_with_offset(reader: &P, offset: usize) -> Self {
- reader.get_pos() - 1 + offset..reader.get_pos() - 1 + offset
+ reader.position() - 1 + offset..reader.position() - 1 + offset
}
fn push_str(&mut self, str: &str) {