aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-11 23:04:09 +0200
committerMartin Fischer <martin@push-f.com>2023-08-19 06:41:55 +0200
commit8bc84de0213d60e810620a97449f83dc1bc9f13e (patch)
tree8f8a1b0ae13015281b1fca7a813d41656c5e16a1 /src
parent2c6021ffa738b38be9a51a6ba4872d018404afc1 (diff)
break!: privatize PosTrackingReader fields
Diffstat (limited to 'src')
-rw-r--r--src/spans.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/spans.rs b/src/spans.rs
index 4333bd1..c3d269d 100644
--- a/src/spans.rs
+++ b/src/spans.rs
@@ -12,7 +12,7 @@
use std::ops::Range;
-use crate::Reader;
+use crate::{IntoReader, Reader};
/// A trait to be implemented by readers that track their own position.
pub trait GetPos {
@@ -23,9 +23,19 @@ pub trait GetPos {
/// Wraps a [`Reader`] so that it implements [`GetPos`].
pub struct PosTrackingReader<R> {
/// The wrapped reader.
- pub reader: R,
+ reader: R,
/// The current position.
- pub position: usize,
+ position: usize,
+}
+
+impl<R> PosTrackingReader<R> {
+ /// Wraps the given [`Reader`] so that it implements [`GetPos`] with the position starting from 0.
+ pub fn new<'a>(into_reader: impl IntoReader<'a, Reader = R>) -> Self {
+ Self {
+ reader: into_reader.into_reader(),
+ position: 0,
+ }
+ }
}
impl<R> GetPos for PosTrackingReader<R> {