File tree 1 file changed +6
-2
lines changed
src/exercises/concurrency 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ struct CrawlState {
73
73
domain : String ,
74
74
visited_pages : std:: collections:: HashSet < String > ,
75
75
}
76
+
76
77
impl CrawlState {
77
78
fn new ( start_url : & Url ) -> CrawlState {
78
79
let mut visited_pages = std:: collections:: HashSet :: new ( ) ;
@@ -83,13 +84,16 @@ impl CrawlState {
83
84
}
84
85
}
85
86
86
- fn visit_links ( & self , url : & Url ) -> bool {
87
+ /// Determine whether links within the given page should be extracted.
88
+ fn should_extract_links ( & self , url : & Url ) -> bool {
87
89
let Some ( url_domain) = url. domain ( ) else {
88
90
return false ;
89
91
} ;
90
92
url_domain == self . domain
91
93
}
92
94
95
+ /// Mark the given page as visited, returning true if it had already
96
+ /// been visited.
93
97
fn mark_visited ( & mut self , url : & Url ) -> bool {
94
98
self . visited_pages . insert ( url. as_str ( ) . to_string ( ) )
95
99
}
@@ -146,7 +150,7 @@ fn control_crawl(
146
150
Ok ( link_urls) => {
147
151
for url in link_urls {
148
152
if crawl_state. mark_visited ( & url) {
149
- let extract_links = crawl_state. visit_links ( & url) ;
153
+ let extract_links = crawl_state. should_extract_links ( & url) ;
150
154
let crawl_command = CrawlCommand { url, extract_links } ;
151
155
command_sender. send ( crawl_command) . unwrap ( ) ;
152
156
pending_urls += 1 ;
You can’t perform that action at this time.
0 commit comments