@@ -5,8 +5,8 @@ pub use regex::Regex;
55use std:: io:: prelude:: * ;
66use std:: io:: { self , BufReader } ;
77use std:: sync:: mpsc:: { channel, Receiver } ;
8+ use std:: thread;
89use std:: { fmt, time} ;
9- use std:: { result, thread} ;
1010
1111#[ derive( Debug ) ]
1212enum PipeError {
@@ -29,14 +29,14 @@ pub enum ReadUntil {
2929}
3030
3131impl fmt:: Display for ReadUntil {
32- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
32+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
3333 let printable = match self {
34- ReadUntil :: String ( ref s) if s == "\n " => "\\ n (newline)" . to_string ( ) ,
35- ReadUntil :: String ( ref s) if s == "\r " => "\\ r (carriage return)" . to_string ( ) ,
36- ReadUntil :: String ( ref s) => format ! ( "\" {}\" " , s ) ,
37- ReadUntil :: Regex ( ref r) => format ! ( "Regex: \" {}\" " , r ) ,
38- ReadUntil :: EOF => "EOF (End of File)" . to_string ( ) ,
39- ReadUntil :: NBytes ( n) => format ! ( "reading {} bytes" , n ) ,
34+ ReadUntil :: String ( ref s) if s == "\n " => "\\ n (newline)" . to_owned ( ) ,
35+ ReadUntil :: String ( ref s) if s == "\r " => "\\ r (carriage return)" . to_owned ( ) ,
36+ ReadUntil :: String ( ref s) => format ! ( "\" {s }\" " ) ,
37+ ReadUntil :: Regex ( ref r) => format ! ( "Regex: \" {r }\" " ) ,
38+ ReadUntil :: EOF => "EOF (End of File)" . to_owned ( ) ,
39+ ReadUntil :: NBytes ( n) => format ! ( "reading {n } bytes" ) ,
4040 ReadUntil :: Any ( ref v) => {
4141 let mut res = Vec :: new ( ) ;
4242 for r in v {
@@ -45,7 +45,7 @@ impl fmt::Display for ReadUntil {
4545 res. join ( ", " )
4646 }
4747 } ;
48- write ! ( f, "{}" , printable )
48+ write ! ( f, "{printable}" )
4949 }
5050}
5151
@@ -98,12 +98,12 @@ pub fn find(needle: &ReadUntil, buffer: &str, eof: bool) -> Option<(usize, usize
9898 }
9999}
100100
101- /// Options for NBReader
101+ /// Options for ` NBReader`
102102///
103103/// - timeout:
104- /// + `None`: read_until is blocking forever. This is probably not what you want
104+ /// + `None`: ` read_until` is blocking forever. This is probably not what you want
105105/// + `Some(millis)`: after millis milliseconds a timeout error is raised
106- /// - strip_ansi_escape_codes: Whether to filter out escape codes, such as colors.
106+ /// - ` strip_ansi_escape_codes` : Whether to filter out escape codes, such as colors.
107107#[ derive( Default ) ]
108108pub struct Options {
109109 pub timeout_ms : Option < u64 > ,
@@ -116,7 +116,7 @@ pub struct Options {
116116/// Internally a thread is spawned and the output is read ahead so when
117117/// calling `read_line` or `read_until` it reads from an internal buffer
118118pub struct NBReader {
119- reader : Receiver < result :: Result < PipedChar , PipeError > > ,
119+ reader : Receiver < Result < PipedChar , PipeError > > ,
120120 buffer : String ,
121121 eof : bool ,
122122 timeout : Option < time:: Duration > ,
@@ -192,7 +192,7 @@ impl NBReader {
192192 Err ( PipeError :: IO ( ref err) ) => {
193193 // For an explanation of why we use `raw_os_error` see:
194194 // https://github.com/zhiburt/ptyprocess/commit/df003c8e3ff326f7d17bc723bc7c27c50495bb62
195- self . eof = err. raw_os_error ( ) == Some ( 5 )
195+ self . eof = err. raw_os_error ( ) == Some ( 5 ) ;
196196 }
197197 }
198198 }
@@ -207,7 +207,7 @@ impl NBReader {
207207 ///
208208 /// There are different modes:
209209 ///
210- /// - `ReadUntil::String` searches for string (use '\n'.to_string() to search for newline).
210+ /// - `ReadUntil::String` searches for string (use '\n'.` to_string()` to search for newline).
211211 /// Returns not yet read data in first String, and needle in second String
212212 /// - `ReadUntil::Regex` searches for regex
213213 /// Returns not yet read data in first String and matched regex in second String
@@ -310,8 +310,8 @@ mod tests {
310310 let f = io:: Cursor :: new ( "a melon\r \n " ) ;
311311 let mut r = NBReader :: new ( f, Options :: default ( ) ) ;
312312 assert_eq ! (
313- ( "a melon" . to_string ( ) , "\r \n " . to_string ( ) ) ,
314- r. read_until( & ReadUntil :: String ( "\r \n " . to_string ( ) ) )
313+ ( "a melon" . to_owned ( ) , "\r \n " . to_owned ( ) ) ,
314+ r. read_until( & ReadUntil :: String ( "\r \n " . to_owned ( ) ) )
315315 . expect( "cannot read line" )
316316 ) ;
317317 // check for EOF
@@ -328,7 +328,7 @@ mod tests {
328328 let mut r = NBReader :: new ( f, Options :: default ( ) ) ;
329329 let re = Regex :: new ( r"^\d{4}-\d{2}-\d{2}$" ) . unwrap ( ) ;
330330 assert_eq ! (
331- ( "" . to_string ( ) , "2014-03-15" . to_string ( ) ) ,
331+ ( "" . to_owned ( ) , "2014-03-15" . to_owned ( ) ) ,
332332 r. read_until( & ReadUntil :: Regex ( re) )
333333 . expect( "regex doesn't match" )
334334 ) ;
@@ -340,7 +340,7 @@ mod tests {
340340 let mut r = NBReader :: new ( f, Options :: default ( ) ) ;
341341 let re = Regex :: new ( r"-\d{2}-" ) . unwrap ( ) ;
342342 assert_eq ! (
343- ( "2014" . to_string ( ) , "-03-" . to_string ( ) ) ,
343+ ( "2014" . to_owned ( ) , "-03-" . to_owned ( ) ) ,
344344 r. read_until( & ReadUntil :: Regex ( re) )
345345 . expect( "regex doesn't match" )
346346 ) ;
@@ -351,15 +351,15 @@ mod tests {
351351 let f = io:: Cursor :: new ( "abcdef" ) ;
352352 let mut r = NBReader :: new ( f, Options :: default ( ) ) ;
353353 assert_eq ! (
354- ( "" . to_string ( ) , "ab" . to_string ( ) ) ,
354+ ( "" . to_owned ( ) , "ab" . to_owned ( ) ) ,
355355 r. read_until( & ReadUntil :: NBytes ( 2 ) ) . expect( "2 bytes" )
356356 ) ;
357357 assert_eq ! (
358- ( "" . to_string ( ) , "cde" . to_string ( ) ) ,
358+ ( "" . to_owned ( ) , "cde" . to_owned ( ) ) ,
359359 r. read_until( & ReadUntil :: NBytes ( 3 ) ) . expect( "3 bytes" )
360360 ) ;
361361 assert_eq ! (
362- ( "" . to_string ( ) , "f" . to_string ( ) ) ,
362+ ( "" . to_owned ( ) , "f" . to_owned ( ) ) ,
363363 r. read_until( & ReadUntil :: NBytes ( 4 ) ) . expect( "4 bytes" )
364364 ) ;
365365 }
@@ -371,12 +371,12 @@ mod tests {
371371
372372 let result = r
373373 . read_until ( & ReadUntil :: Any ( vec ! [
374- ReadUntil :: String ( "two" . to_string ( ) ) ,
375- ReadUntil :: String ( "one" . to_string ( ) ) ,
374+ ReadUntil :: String ( "two" . to_owned ( ) ) ,
375+ ReadUntil :: String ( "one" . to_owned ( ) ) ,
376376 ] ) )
377377 . expect ( "finding string" ) ;
378378
379- assert_eq ! ( ( "zero " . to_string ( ) , "one" . to_string ( ) ) , result) ;
379+ assert_eq ! ( ( "zero " . to_owned ( ) , "one" . to_owned ( ) ) , result) ;
380380 }
381381
382382 #[ test]
@@ -386,12 +386,12 @@ mod tests {
386386
387387 let result = r
388388 . read_until ( & ReadUntil :: Any ( vec ! [
389- ReadUntil :: String ( "hello" . to_string ( ) ) ,
390- ReadUntil :: String ( "hell" . to_string ( ) ) ,
389+ ReadUntil :: String ( "hello" . to_owned ( ) ) ,
390+ ReadUntil :: String ( "hell" . to_owned ( ) ) ,
391391 ] ) )
392392 . expect ( "finding string" ) ;
393393
394- assert_eq ! ( ( "hi " . to_string ( ) , "hell" . to_string ( ) ) , result) ;
394+ assert_eq ! ( ( "hi " . to_owned ( ) , "hell" . to_owned ( ) ) , result) ;
395395 }
396396
397397 #[ test]
@@ -400,7 +400,7 @@ mod tests {
400400 let mut r = NBReader :: new ( f, Options :: default ( ) ) ;
401401 r. read_until ( & ReadUntil :: NBytes ( 2 ) ) . expect ( "2 bytes" ) ;
402402 assert_eq ! (
403- ( "" . to_string ( ) , "rem ipsum dolor sit amet" . to_string ( ) ) ,
403+ ( "" . to_owned ( ) , "rem ipsum dolor sit amet" . to_owned ( ) ) ,
404404 r. read_until( & ReadUntil :: EOF ) . expect( "reading until EOF" )
405405 ) ;
406406 }
@@ -416,9 +416,9 @@ mod tests {
416416 } ,
417417 ) ;
418418 let bytes = r
419- . read_until ( & ReadUntil :: String ( "Hello" . to_string ( ) ) )
419+ . read_until ( & ReadUntil :: String ( "Hello" . to_owned ( ) ) )
420420 . unwrap ( ) ;
421- assert_eq ! ( bytes, ( "" . to_string ( ) , "Hello" . to_string ( ) ) ) ;
421+ assert_eq ! ( bytes, ( "" . to_owned ( ) , "Hello" . to_owned ( ) ) ) ;
422422 assert_eq ! ( None , r. try_read( ) ) ;
423423 }
424424
@@ -433,9 +433,9 @@ mod tests {
433433 } ,
434434 ) ;
435435 let bytes = r
436- . read_until ( & ReadUntil :: String ( "Hello" . to_string ( ) ) )
436+ . read_until ( & ReadUntil :: String ( "Hello" . to_owned ( ) ) )
437437 . unwrap ( ) ;
438- assert_eq ! ( bytes, ( "" . to_string ( ) , "Hello" . to_string ( ) ) ) ;
438+ assert_eq ! ( bytes, ( "" . to_owned ( ) , "Hello" . to_owned ( ) ) ) ;
439439 assert_eq ! ( None , r. try_read( ) ) ;
440440 }
441441
0 commit comments