@@ -4,8 +4,14 @@ use crate::{
4
4
} ;
5
5
use std:: io;
6
6
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:
8
13
/// OS -> (parent) line provider buffer -> our buffer -> caller's output buffer
14
+ /// which won't make this very efficient for huge bandwidths.
9
15
pub struct ReadWithSidebands < ' a , T , F >
10
16
where
11
17
T : io:: Read ,
46
52
T : io:: Read ,
47
53
F : FnMut ( bool , & [ u8 ] ) ,
48
54
{
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.
49
59
pub fn with_progress_handler ( parent : & ' a mut Provider < T > , handle_progress : F ) -> Self {
50
60
ReadWithSidebands {
51
61
parent,
56
66
}
57
67
}
58
68
69
+ /// Create a new instance without a progress handler.
59
70
pub fn without_progress_handler ( parent : & ' a mut Provider < T > ) -> Self {
60
71
ReadWithSidebands {
61
72
parent,
@@ -66,18 +77,23 @@ where
66
77
}
67
78
}
68
79
80
+ /// Forwards to the parent [Provider::reset_with()]
69
81
pub fn reset_with ( & mut self , delimiters : & ' static [ PacketLine < ' static > ] ) {
70
82
self . parent . reset_with ( delimiters)
71
83
}
72
84
85
+ /// Forwards to the parent [Provider::stopped_at()]
73
86
pub fn stopped_at ( & self ) -> Option < PacketLine < ' static > > {
74
87
self . parent . stopped_at
75
88
}
76
89
90
+ /// Set or unset the progress handler.
77
91
pub fn set_progress_handler ( & mut self , handle_progress : Option < F > ) {
78
92
self . handle_progress = handle_progress;
79
93
}
80
94
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()].
81
97
pub fn peek_data_line ( & mut self ) -> Option < io:: Result < Result < & [ u8 ] , crate :: decode:: Error > > > {
82
98
match self . parent . peek_line ( ) {
83
99
Some ( Ok ( Ok ( line) ) ) => match line {
0 commit comments