Skip to content

Commit e277cce

Browse files
committed
docs for ReadWithSidebands
1 parent 832f7f3 commit e277cce

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

git-packetline/src/provider/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ where
186186
}
187187

188188
/// Return this instance as implementor of [`Read`][io::Read] assuming side bands to be used in all received packet lines.
189-
/// Each invocation of [`read_line()`][io::Read::read_line()] returns a packet line.
189+
/// Each invocation of [`read_line()`][io::BufRead::read_line()] returns a packet line.
190190
///
191191
/// Progress or error information will be passed to the given `handle_progress(is_error, text)` function, with `is_error: bool`
192192
/// being true in case the `text` is to be interpreted as error.

git-packetline/src/provider/read.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ use crate::{
44
};
55
use std::io;
66

7-
/// Note: Reading from this intermediary copies bytes 3 times:
7+
/// An implementor of [`BufRead`][io::BufRead] yielding packet lines on each call to [`read_line()`][io::BufRead::read_line()].
8+
/// It's also possible to hide the underlying packet lines using the [`Read`][io::Read] implementation which is useful
9+
/// if they represent binary data, like the one of a pack file.
10+
///
11+
/// # Performance Notice
12+
/// Reading from this intermediary copies bytes 3 times:
813
/// OS -> (parent) line provider buffer -> our buffer -> caller's output buffer
14+
/// which won't make this very efficient for huge bandwidths.
915
pub struct ReadWithSidebands<'a, T, F>
1016
where
1117
T: io::Read,
@@ -46,6 +52,10 @@ where
4652
T: io::Read,
4753
F: FnMut(bool, &[u8]),
4854
{
55+
/// Create a new instance with the given `parent` provider and the `handle_progress` function.
56+
///
57+
/// Progress or error information will be passed to the given `handle_progress(is_error, text)` function, with `is_error: bool`
58+
/// being true in case the `text` is to be interpreted as error.
4959
pub fn with_progress_handler(parent: &'a mut Provider<T>, handle_progress: F) -> Self {
5060
ReadWithSidebands {
5161
parent,
@@ -56,6 +66,7 @@ where
5666
}
5767
}
5868

69+
/// Create a new instance without a progress handler.
5970
pub fn without_progress_handler(parent: &'a mut Provider<T>) -> Self {
6071
ReadWithSidebands {
6172
parent,
@@ -66,18 +77,23 @@ where
6677
}
6778
}
6879

80+
/// Forwards to the parent [Provider::reset_with()]
6981
pub fn reset_with(&mut self, delimiters: &'static [PacketLine<'static>]) {
7082
self.parent.reset_with(delimiters)
7183
}
7284

85+
/// Forwards to the parent [Provider::stopped_at()]
7386
pub fn stopped_at(&self) -> Option<PacketLine<'static>> {
7487
self.parent.stopped_at
7588
}
7689

90+
/// Set or unset the progress handler.
7791
pub fn set_progress_handler(&mut self, handle_progress: Option<F>) {
7892
self.handle_progress = handle_progress;
7993
}
8094

95+
/// Effectively forwards to the parent [Provider::peek_line()], allowing to see what would be returned
96+
/// next on a call to [`read_line()`][io::BufRead::read_line()].
8197
pub fn peek_data_line(&mut self) -> Option<io::Result<Result<&[u8], crate::decode::Error>>> {
8298
match self.parent.peek_line() {
8399
Some(Ok(Ok(line))) => match line {

0 commit comments

Comments
 (0)