Skip to content

Commit f1ed28c

Browse files
committed
style: cargo fmt [skip ci]
1 parent de1e0df commit f1ed28c

4 files changed

Lines changed: 70 additions & 36 deletions

File tree

engines/qq/src/api/format.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ impl QQFormat {
3535
pub fn to_filename(&self, filename: &str) -> String {
3636
concat_string!(self.as_format_id(), filename, self.as_extension())
3737
}
38-
38+
3939
/// Determine the mode according to the context
4040
pub fn from_context(ctx: &Context) -> QQFormat {
4141
let cookie = extract_cookie(ctx);
42-
42+
4343
if cookie.is_some() {
4444
if ctx.enable_flac {
4545
QQFormat::MemberFlac
@@ -62,16 +62,25 @@ mod tests {
6262

6363
#[test]
6464
fn test_format_guest_mp3() {
65-
assert_eq!(QQFormat::GuestMp3.to_filename(FILE), concat_string!("M500", FILE, ".mp3"));
65+
assert_eq!(
66+
QQFormat::GuestMp3.to_filename(FILE),
67+
concat_string!("M500", FILE, ".mp3")
68+
);
6669
}
6770

6871
#[test]
6972
fn test_format_member_mp3() {
70-
assert_eq!(QQFormat::MemberMp3.to_filename(FILE), concat_string!("M800", FILE, ".mp3"));
73+
assert_eq!(
74+
QQFormat::MemberMp3.to_filename(FILE),
75+
concat_string!("M800", FILE, ".mp3")
76+
);
7177
}
7278

7379
#[test]
7480
fn test_format_member_flac() {
75-
assert_eq!(QQFormat::MemberFlac.to_filename(FILE), concat_string!("F000", FILE, ".flac"));
81+
assert_eq!(
82+
QQFormat::MemberFlac.to_filename(FILE),
83+
concat_string!("F000", FILE, ".flac")
84+
);
7685
}
7786
}

engines/qq/src/api/identifier.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt::Display, error::Error};
1+
use std::{error::Error, fmt::Display};
22

33
#[derive(Clone, Debug, PartialEq)]
44
pub struct QQResourceIdentifier<'a> {
@@ -29,7 +29,11 @@ pub type DeserializationResult<T> = Result<T, DeserializationFailed>;
2929

3030
impl Display for DeserializationFailed {
3131
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32-
write!(f, "the attempt to extract “{}” from 'serialized' parameter failed", self.0)
32+
write!(
33+
f,
34+
"the attempt to extract “{}” from 'serialized' parameter failed",
35+
self.0
36+
)
3337
}
3438
}
3539

@@ -53,10 +57,13 @@ mod tests {
5357
fn test_identifier_deserialization() {
5458
let identifier = "mid113:::file113";
5559

56-
assert_eq!(QQResourceIdentifier::deserialize(identifier).unwrap(), QQResourceIdentifier {
57-
mid: "mid113",
58-
file: "file113",
59-
});
60+
assert_eq!(
61+
QQResourceIdentifier::deserialize(identifier).unwrap(),
62+
QQResourceIdentifier {
63+
mid: "mid113",
64+
file: "file113",
65+
}
66+
);
6067
}
6168

6269
#[test]

engines/qq/src/api/typing.rs

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use concat_string::concat_string;
44
use serde::Deserialize;
5-
use unm_types::{Song, Album, Artist};
5+
use unm_types::{Album, Artist, Song};
66

77
use super::identifier::QQResourceIdentifier;
88

@@ -33,7 +33,7 @@ pub struct QQSongEntry {
3333
pub singer: Vec<QQSongSinger>,
3434

3535
/// The media ID of this song entry.
36-
///
36+
///
3737
/// If no `media_mid` is provided, we return an empty string.
3838
/// You may want to filter it with [`Iterator::filter`].
3939
#[serde(default)]
@@ -64,7 +64,7 @@ pub struct QQSingleResponse {
6464
pub sip: Vec<String>,
6565

6666
/// The segment of audio URLs to receive.
67-
pub midurlinfo: Vec<QQSingleUrlInfo>
67+
pub midurlinfo: Vec<QQSingleUrlInfo>,
6868
}
6969

7070
#[derive(Debug, Deserialize)]
@@ -74,7 +74,7 @@ pub struct QQSingleUrlInfo {
7474
pub filename: String,
7575

7676
/// The URL segment of this audio.
77-
///
77+
///
7878
/// You can combine this segment with the server
7979
/// in the `sip` field of [`QQSingleResponse`].
8080
pub purl: String,
@@ -90,18 +90,22 @@ impl From<QQSongEntry> for Song {
9090
Album::builder()
9191
.id(entry.albumid.to_string())
9292
.name(entry.albumname)
93-
.build()
93+
.build(),
9494
))
9595
.artists(entry.singer.into_iter().map(Into::into).collect())
9696
.context({
9797
let mut ctx = HashMap::new();
9898
let songmid = entry.songmid;
9999
let media_mid = entry.media_mid;
100100

101-
ctx.insert("identifier".into(), QQResourceIdentifier {
102-
mid: &songmid,
103-
file: &media_mid,
104-
}.serialize());
101+
ctx.insert(
102+
"identifier".into(),
103+
QQResourceIdentifier {
104+
mid: &songmid,
105+
file: &media_mid,
106+
}
107+
.serialize(),
108+
);
105109
ctx.insert("songmid".into(), songmid);
106110
ctx.insert("media_mid".into(), media_mid);
107111

@@ -124,13 +128,15 @@ impl QQSingleResponse {
124128
pub fn get_url(&self) -> Result<String, FieldNotPickable> {
125129
log::info!("Extracting the URL from the single response…");
126130

127-
let server = self.sip
131+
let server = self
132+
.sip
128133
.get(fastrand::usize(0..self.sip.len()))
129134
.ok_or(FieldNotPickable("sip"))?;
130-
let url_info = self.midurlinfo
135+
let url_info = self
136+
.midurlinfo
131137
.get(0)
132138
.ok_or(FieldNotPickable("midurlinfo"))?;
133-
139+
134140
Ok(concat_string!(server, url_info.purl))
135141
}
136142
}
@@ -155,29 +161,36 @@ mod tests {
155161
let single_response = QQSingleResponse {
156162
sip: vec!["http://helloworld.com/".into()],
157163
midurlinfo: vec![QQSingleUrlInfo {
158-
filename: "filename".into(), purl: "purl?114514".into()
164+
filename: "filename".into(),
165+
purl: "purl?114514".into(),
159166
}],
160167
};
161168

162-
assert_eq!(single_response.get_url().unwrap(), "http://helloworld.com/purl?114514");
169+
assert_eq!(
170+
single_response.get_url().unwrap(),
171+
"http://helloworld.com/purl?114514"
172+
);
163173
}
164174

165175
#[test]
166176
fn test_single_response_get_url_with_multiple_sip() {
167177
let single_response = QQSingleResponse {
168-
sip: vec!["http://helloworld.com/".into(), "http://helloworld.org/".into()],
169-
midurlinfo: vec![
170-
QQSingleUrlInfo {
171-
filename: "filename".into(), purl: "purl?114514".into()
172-
},
178+
sip: vec![
179+
"http://helloworld.com/".into(),
180+
"http://helloworld.org/".into(),
173181
],
182+
midurlinfo: vec![QQSingleUrlInfo {
183+
filename: "filename".into(),
184+
purl: "purl?114514".into(),
185+
}],
174186
};
175187

176188
let data = single_response.get_url().unwrap();
177189
assert!(vec![
178190
"http://helloworld.com/purl?114514",
179191
"http://helloworld.org/purl?114514"
180-
].contains(&data.as_str()));
192+
]
193+
.contains(&data.as_str()));
181194
}
182195

183196
#[test]
@@ -186,14 +199,19 @@ mod tests {
186199
sip: vec!["http://helloworld.com/".into()],
187200
midurlinfo: vec![
188201
QQSingleUrlInfo {
189-
filename: "filename".into(), purl: "purl?114514".into()
202+
filename: "filename".into(),
203+
purl: "purl?114514".into(),
190204
},
191205
QQSingleUrlInfo {
192-
filename: "DO_NOT_PICK_THIS".into(), purl: "!!!DONTPICKTHIS!!!".into()
206+
filename: "DO_NOT_PICK_THIS".into(),
207+
purl: "!!!DONTPICKTHIS!!!".into(),
193208
},
194209
],
195210
};
196211

197-
assert_eq!(single_response.get_url().unwrap(), "http://helloworld.com/purl?114514");
212+
assert_eq!(
213+
single_response.get_url().unwrap(),
214+
"http://helloworld.com/purl?114514"
215+
);
198216
}
199-
}
217+
}

engines/qq/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
pub mod api;
2323

24-
use api::{search_by_keyword, retrieve_single};
24+
use api::{retrieve_single, search_by_keyword};
2525
use async_trait::async_trait;
2626
use log::{debug, info};
2727
use unm_engine::interface::Engine;

0 commit comments

Comments
 (0)