File tree Expand file tree Collapse file tree 13 files changed +100
-106
lines changed
no-listing-02-using-search-in-run/src
output-only-04-no-matches/src
listing-12-23-reproduced/src
listing-12-24-reproduced/src Expand file tree Collapse file tree 13 files changed +100
-106
lines changed Original file line number Diff line number Diff line change @@ -25,10 +25,10 @@ fn main() {
2525}
2626
2727// ANCHOR: here
28- pub struct Config {
29- pub query : String ,
30- pub percorso_file : String ,
31- pub ignora_maiuscole : bool ,
28+ struct Config {
29+ query : String ,
30+ percorso_file : String ,
31+ ignora_maiuscole : bool ,
3232}
3333// ANCHOR_END: here
3434
Original file line number Diff line number Diff line change @@ -19,10 +19,10 @@ fn main() {
1919 }
2020}
2121
22- pub struct Config {
23- pub query : String ,
24- pub percorso_file : String ,
25- pub ignora_maiuscole : bool ,
22+ struct Config {
23+ query : String ,
24+ percorso_file : String ,
25+ ignora_maiuscole : bool ,
2626}
2727
2828// ANCHOR: here
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ fn main() {
2121}
2222// ANCHOR_END: here
2323
24- pub struct Config {
25- pub query : String ,
26- pub percorso_file : String ,
27- pub ignora_maiuscole : bool ,
24+ struct Config {
25+ query : String ,
26+ percorso_file : String ,
27+ ignora_maiuscole : bool ,
2828}
2929
3030impl Config {
Original file line number Diff line number Diff line change 1- use std:: error:: Error ;
2- use std:: fs;
3-
4- pub struct Config {
5- pub query : String ,
6- pub percorso_file : String ,
7- }
8-
9- impl Config {
10- pub fn build ( args : & [ String ] ) -> Result < Config , & ' static str > {
11- if args. len ( ) < 3 {
12- return Err ( "Non ci sono abbastanza argomenti" ) ;
13- }
14-
15- let query = args[ 1 ] . clone ( ) ;
16- let percorso_file = args[ 2 ] . clone ( ) ;
17-
18- Ok ( Config { query, percorso_file } )
19- }
20- }
21-
22- // ANCHOR: here
23- pub fn esegui ( config : Config ) -> Result < ( ) , Box < dyn Error > > {
24- let contenuto = fs:: read_to_string ( config. percorso_file ) ?;
25-
26- for line in cerca ( & config. query , & contenuto) {
27- println ! ( "{line}" ) ;
28- }
29-
30- Ok ( ( ) )
31- }
32- // ANCHOR_END: here
33-
341pub fn cerca < ' a > ( query : & str , contenuto : & ' a str ) -> Vec < & ' a str > {
352 let mut risultato = Vec :: new ( ) ;
363
Original file line number Diff line number Diff line change 11use std:: env;
2+ use std:: error:: Error ;
3+ use std:: fs;
24use std:: process;
35
4- use minigrep:: Config ;
6+ use minigrep:: cerca ;
57
68fn main ( ) {
79 let args: Vec < String > = env:: args ( ) . collect ( ) ;
@@ -11,8 +13,36 @@ fn main() {
1113 process:: exit ( 1 ) ;
1214 } ) ;
1315
14- if let Err ( e) = minigrep :: esegui ( config) {
16+ if let Err ( e) = esegui ( config) {
1517 println ! ( "Errore nell'applicazione: {e}" ) ;
1618 process:: exit ( 1 ) ;
1719 }
1820}
21+
22+ struct Config {
23+ query : String ,
24+ percorso_file : String ,
25+ }
26+
27+ impl Config {
28+ fn build ( args : & [ String ] ) -> Result < Config , & ' static str > {
29+ if args. len ( ) < 3 {
30+ return Err ( "Non ci sono abbastanza argomenti" ) ;
31+ }
32+
33+ let query = args[ 1 ] . clone ( ) ;
34+ let percorso_file = args[ 2 ] . clone ( ) ;
35+
36+ Ok ( Config { query, percorso_file } )
37+ }
38+ }
39+
40+ fn esegui ( config : Config ) -> Result < ( ) , Box < dyn Error > > {
41+ let contenuto = fs:: read_to_string ( config. percorso_file ) ?;
42+
43+ for line in cerca ( & config. query , & contenuto) {
44+ println ! ( "{line}" ) ;
45+ }
46+
47+ Ok ( ( ) )
48+ }
Original file line number Diff line number Diff line change 1- use std:: error:: Error ;
2- use std:: fs;
3-
4- pub struct Config {
5- pub query : String ,
6- pub percorso_file : String ,
7- }
8-
9- impl Config {
10- pub fn build ( args : & [ String ] ) -> Result < Config , & ' static str > {
11- if args. len ( ) < 3 {
12- return Err ( "Non ci sono abbastanza argomenti" ) ;
13- }
14-
15- let query = args[ 1 ] . clone ( ) ;
16- let percorso_file = args[ 2 ] . clone ( ) ;
17-
18- Ok ( Config { query, percorso_file } )
19- }
20- }
21-
22- // ANCHOR: here
23- pub fn esegui ( config : Config ) -> Result < ( ) , Box < dyn Error > > {
24- let contenuto = fs:: read_to_string ( config. percorso_file ) ?;
25-
26- for line in cerca ( & config. query , & contenuto) {
27- println ! ( "{line}" ) ;
28- }
29-
30- Ok ( ( ) )
31- }
32- // ANCHOR_END: here
33-
341pub fn cerca < ' a > ( query : & str , contenuto : & ' a str ) -> Vec < & ' a str > {
352 let mut risultato = Vec :: new ( ) ;
363
Original file line number Diff line number Diff line change 11use std:: env;
2+ use std:: error:: Error ;
3+ use std:: fs;
24use std:: process;
35
4- use minigrep:: Config ;
6+ use minigrep:: cerca ;
57
68fn main ( ) {
79 let args: Vec < String > = env:: args ( ) . collect ( ) ;
@@ -11,8 +13,36 @@ fn main() {
1113 process:: exit ( 1 ) ;
1214 } ) ;
1315
14- if let Err ( e) = minigrep :: esegui ( config) {
16+ if let Err ( e) = esegui ( config) {
1517 println ! ( "Errore nell'applicazione: {e}" ) ;
1618 process:: exit ( 1 ) ;
1719 }
1820}
21+
22+ struct Config {
23+ query : String ,
24+ percorso_file : String ,
25+ }
26+
27+ impl Config {
28+ fn build ( args : & [ String ] ) -> Result < Config , & ' static str > {
29+ if args. len ( ) < 3 {
30+ return Err ( "Non ci sono abbastanza argomenti" ) ;
31+ }
32+
33+ let query = args[ 1 ] . clone ( ) ;
34+ let percorso_file = args[ 2 ] . clone ( ) ;
35+
36+ Ok ( Config { query, percorso_file } )
37+ }
38+ }
39+
40+ fn esegui ( config : Config ) -> Result < ( ) , Box < dyn Error > > {
41+ let contenuto = fs:: read_to_string ( config. percorso_file ) ?;
42+
43+ for line in cerca ( & config. query , & contenuto) {
44+ println ! ( "{line}" ) ;
45+ }
46+
47+ Ok ( ( ) )
48+ }
Original file line number Diff line number Diff line change @@ -19,10 +19,10 @@ fn main() {
1919 }
2020}
2121
22- pub struct Config {
23- pub query : String ,
24- pub percorso_file : String ,
25- pub ignora_maiuscole : bool ,
22+ struct Config {
23+ query : String ,
24+ percorso_file : String ,
25+ ignora_maiuscole : bool ,
2626}
2727
2828// ANCHOR: ch13
Original file line number Diff line number Diff line change @@ -25,10 +25,10 @@ fn main() {
2525}
2626// ANCHOR_END: ch13
2727
28- pub struct Config {
29- pub query : String ,
30- pub percorso_file : String ,
31- pub ignora_maiuscole : bool ,
28+ struct Config {
29+ query : String ,
30+ percorso_file : String ,
31+ ignora_maiuscole : bool ,
3232}
3333
3434impl Config {
Original file line number Diff line number Diff line change @@ -23,10 +23,10 @@ fn main() {
2323}
2424// ANCHOR_END: here
2525
26- pub struct Config {
27- pub query : String ,
28- pub percorso_file : String ,
29- pub ignora_maiuscole : bool ,
26+ struct Config {
27+ query : String ,
28+ percorso_file : String ,
29+ ignora_maiuscole : bool ,
3030}
3131
3232impl Config {
You can’t perform that action at this time.
0 commit comments