@@ -8,15 +8,14 @@ use std::sync::mpsc::{Receiver, channel};
88use std:: thread;
99use std:: { fmt, time} ;
1010
11- /// Options for `NBReader`
12- ///
13- /// - timeout:
14- /// + `None`: `read_until` is blocking forever. This is probably not what you want
15- /// + `Some(millis)`: after millis milliseconds a timeout error is raised
16- /// - `strip_ansi_escape_codes`: Whether to filter out escape codes, such as colors.
11+ /// Options for [`NBReader`]
1712#[ derive( Default ) ]
1813pub struct Options {
14+ /// `None`: `read_until` is blocking forever. This is probably not what you want
15+ ///
16+ /// `Some(millis)`: after millis milliseconds a timeout error is raised
1917 pub timeout_ms : Option < u64 > ,
18+ /// Whether to filter out escape codes, such as colors.
2019 pub strip_ansi_escape_codes : bool ,
2120}
2221
@@ -35,10 +34,10 @@ pub struct NBReader {
3534impl NBReader {
3635 /// Create a new reader instance
3736 ///
38- /// # Arguments:
37+ /// # Arguments
3938 ///
40- /// - f : file like object
41- /// - options: see `Options`
39+ /// - `f` : file like object
40+ /// - ` options` : see [ `Options`]
4241 pub fn new < R : Read + Send + ' static > ( f : R , options : Options ) -> NBReader {
4342 let ( tx, rx) = channel ( ) ;
4443
@@ -87,7 +86,7 @@ impl NBReader {
8786 }
8887 }
8988
90- /// reads all available chars from the read channel and stores them in self. buffer
89+ /// Reads all available chars from the read channel and stores them in [`Self:: buffer`]
9190 fn read_into_buffer ( & mut self ) -> Result < ( ) , Error > {
9291 if self . eof {
9392 return Ok ( ( ) ) ;
@@ -109,24 +108,13 @@ impl NBReader {
109108 Ok ( ( ) )
110109 }
111110
112- /// Read until needle is found (blocking!) and return tuple with:
113- /// 1. yet unread string until and without needle
114- /// 2. matched needle
111+ /// Read until needle is found (blocking!)
115112 ///
116113 /// This methods loops (while reading from the Cursor) until the needle is found.
117114 ///
118- /// There are different modes:
119- ///
120- /// - `ReadUntil::String` searches for string (use '\n'.`to_string()` to search for newline).
121- /// Returns not yet read data in first String, and needle in second String
122- /// - `ReadUntil::Regex` searches for regex
123- /// Returns not yet read data in first String and matched regex in second String
124- /// - `ReadUntil::NBytes` reads maximum n bytes
125- /// Returns n bytes in second String, first String is left empty
126- /// - `ReadUntil::EOF` reads until end of file is reached
127- /// Returns all bytes in second String, first is left empty
128- ///
129- /// Note that when used with a tty the lines end with \r\n
115+ /// Returns a tuple with:
116+ /// 1. yet unread string until and without needle
117+ /// 2. matched needle
130118 ///
131119 /// Returns error if EOF is reached before the needle could be found.
132120 ///
@@ -193,8 +181,9 @@ impl NBReader {
193181 }
194182 }
195183
196- /// Try to read one char from internal buffer. Returns None if
197- /// no char is ready, Some(char) otherwise. This is non-blocking
184+ /// Try to read one char from internal buffer (non-blocking).
185+ ///
186+ /// Returns `None` if no char is ready `Some(char)` otherwise.
198187 pub fn try_read ( & mut self ) -> Option < char > {
199188 // discard eventual errors, EOF will be handled in read_until correctly
200189 let _ = self . read_into_buffer ( ) ;
@@ -207,10 +196,24 @@ impl NBReader {
207196}
208197
209198/// See [`NBReader::read_until`]
199+ ///
200+ /// Note that when used with a tty the lines end with \r\n
210201pub enum ReadUntil {
202+ /// Searches for string (use '\n'.`to_string()` to search for newline).
203+ ///
204+ /// Returns not yet read data in first String, and needle in second String
211205 String ( String ) ,
206+ /// `ReadUntil::Regex` searches for regex
207+ ///
208+ /// Returns not yet read data in first String and matched regex in second String
212209 Regex ( Regex ) ,
210+ /// `ReadUntil::NBytes` reads maximum n bytes
211+ ///
212+ /// Returns n bytes in second String, first String is left empty
213213 NBytes ( usize ) ,
214+ /// `ReadUntil::EOF` reads until end of file is reached
215+ ///
216+ /// Returns all bytes in second String, first is left empty
214217 EOF ,
215218 Any ( Vec < ReadUntil > ) ,
216219}
@@ -237,12 +240,12 @@ impl fmt::Display for ReadUntil {
237240 }
238241}
239242
240- /// find first occurrence of needle within buffer
243+ /// Find first occurrence of needle within buffer
241244///
242245/// # Arguments:
243246///
244- /// - buffer: the currently read buffer from a process which will still grow in the future
245- /// - eof: if the process already sent an EOF or a HUP
247+ /// - ` buffer` : the currently read buffer from a process which will still grow in the future
248+ /// - ` eof` : if the process already sent an EOF or a HUP
246249///
247250/// # Return
248251///
0 commit comments