From bec70ad5c493cd85a4c972cf917f455ace1a88d0 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 17 Aug 2023 07:07:56 +0200 Subject: 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 --- src/spans.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') 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`] 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 { /// The wrapped reader. reader: R, @@ -29,7 +29,7 @@ pub struct PosTrackingReader { } impl PosTrackingReader { - /// 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 PosTrackingReader { } } -impl GetPos for PosTrackingReader { - fn get_pos(&self) -> usize { +impl Position for PosTrackingReader { + fn position(&self) -> usize { self.position } } @@ -64,13 +64,13 @@ impl Span for () { fn push_str(&mut self, _str: &str) {} } -impl Span

for Range { +impl Span

for Range { 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) { -- cgit v1.2.3