Skip to content

Commit 318f28e

Browse files
committed
Fix clippy errors (?)
1 parent 48536b3 commit 318f28e

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

rust/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
types:
2-
cargo test && rm -r ../src/lib/bindings && mv bindings ../src/lib
2+
cargo run --bin export-types

rust/src/core.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
use chrono::{DateTime, Utc, TimeZone};
1+
use chrono::{DateTime, Utc};
22
use chrono_tz::Europe::London;
33
use serde::{Deserialize, Serialize};
44
use ts_rs::TS;
55

66
#[derive(Debug, Serialize, Deserialize, TS)]
7-
#[ts(export)]
87
pub struct Piece {
98
pub composer: String,
109
pub title: String,
1110
}
1211

1312
#[derive(Debug, Serialize, Deserialize, TS)]
14-
#[ts(export)]
1513
pub struct Performer {
1614
pub name: String,
1715
pub instrument: Option<String>,
1816
}
1917

2018
#[derive(Debug, Serialize, Deserialize, TS)]
21-
#[ts(export)]
2219
pub struct Concert {
2320
pub datetime: DateTime<Utc>,
2421
pub url: String,
@@ -36,7 +33,7 @@ pub struct Concert {
3633
pub is_prom: bool,
3734
}
3835

39-
pub fn report_concert(c: &Concert) -> () {
36+
pub fn report_concert(c: &Concert) {
4037
let london_datetime = c.datetime.with_timezone(&London);
4138
eprintln!("Found concert on {}: {}", london_datetime, c.title);
4239
}

rust/src/proms.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub async fn scrape(url: &str, client: &reqwest::Client) -> Vec<core::Concert> {
3636
.for_each(|concert| concerts.push(concert));
3737
}
3838

39-
return concerts;
39+
concerts
4040
}
4141

4242
/// Intermediate struct which contains information about a single concert entry. This does not
@@ -107,8 +107,7 @@ fn parse_single_concert(elem: ElementRef<'_>) -> PromsConcertMetadata {
107107
Selector::parse("li.ev-act-schedule__performance-composer-segments").unwrap();
108108
let pieces: Vec<core::Piece> = elem
109109
.select(&pieces_selector)
110-
.map(|piece_elem| parse_piece(piece_elem))
111-
.filter_map(|x| x)
110+
.filter_map(parse_piece)
112111
.collect();
113112

114113
let performer_selector = Selector::parse(

rust/src/wigmore.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ pub async fn get_concerts(client: &reqwest::Client) -> Vec<core::Concert> {
1313
println!("Scraping Wigmore Hall concerts");
1414
println!("----------------------------------------");
1515

16-
let wigmore_intermediate_concerts = get_api(&client).await;
16+
let wigmore_intermediate_concerts = get_api(client).await;
1717

1818
let mut wigmore_concerts = stream::iter(&wigmore_intermediate_concerts[..40])
19-
.map(|concert| get_full_concert(&concert, &client))
19+
.map(|concert| get_full_concert(concert, client))
2020
.buffer_unordered(10)
2121
.collect::<Vec<Option<core::Concert>>>()
2222
.await
@@ -50,7 +50,7 @@ async fn get_api_page(
5050
page_number
5151
);
5252
let json: serde_json::Value = client.get(url).send().await.unwrap().json().await.unwrap();
53-
let concerts = parse_api(&json["items"].as_array().unwrap());
53+
let concerts = parse_api(json["items"].as_array().unwrap());
5454
(concerts, json["totalPages"].as_u64().unwrap())
5555
}
5656

@@ -94,8 +94,7 @@ async fn get_api(client: &reqwest::Client) -> Vec<WigmoreFrontPageConcert> {
9494
let remaining_concerts: Vec<WigmoreFrontPageConcert> = join_all(futures)
9595
.await
9696
.into_iter()
97-
.map(|(concerts, _)| concerts)
98-
.flatten()
97+
.flat_map(|(concerts, _)| concerts)
9998
.collect();
10099
concerts.extend(remaining_concerts);
101100
concerts
@@ -158,9 +157,8 @@ fn parse_concert_json(
158157
.and_then(|arr| arr[0]["title"].as_str())
159158
.or(Some(""))
160159
.map(|s| decode_html_entities(s).to_string());
161-
match (opt_title, opt_composer) {
162-
(Some(title), Some(composer)) => pieces.push(core::Piece { title, composer }),
163-
_ => (),
160+
if let (Some(title), Some(composer)) = (opt_title, opt_composer) {
161+
pieces.push(core::Piece { title, composer });
164162
}
165163
}
166164
}
@@ -182,12 +180,11 @@ fn parse_concert_json(
182180
for credit in credits {
183181
let opt_artist_name = credit["artist"]["title"].as_str().map(decode_html_entities);
184182
let opt_role = credit["role"].as_str().map(decode_html_entities);
185-
match (opt_artist_name, opt_role) {
186-
(Some(artist_name), Some(role)) => performers.push(core::Performer {
183+
if let (Some(artist_name), Some(role)) = (opt_artist_name, opt_role) {
184+
performers.push(core::Performer {
187185
name: artist_name.to_string(),
188186
instrument: Some(role.to_string()),
189-
}),
190-
_ => (),
187+
});
191188
}
192189
}
193190
}

0 commit comments

Comments
 (0)