1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! NetEase Cloud Music API For Rust.

mod api;
mod client;
mod crypto;
pub mod types;

pub use api::{NcmApi, ResourceType, SearchType};
use thiserror::Error;

#[derive(Debug, Error)]
pub enum ApiErr {
    #[error("reqwest error")]
    ReqwestErr,

    #[error("deserialize error")]
    DeserializeErr,

    #[error("parse url error")]
    ParseUrlErr,

    #[error("read cookie error")]
    ReadCookieErr,

    #[error("write cookie error")]
    WriteCookieErr,
}

type TResult<T> = std::result::Result<T, TError>;
type TError = ApiErr;

#[cfg(test)]
mod tests {
    use super::NcmApi;

    #[tokio::test(flavor = "multi_thread")]
    async fn test_search() {
        let api = NcmApi::default();
        let resp = api.search("mota", None).await;
        assert!(resp.is_ok());

        let res = resp.unwrap();
        let res = res.deserialize_to_implict();
        assert_eq!(res.code, 200);
    }
}