Skip to content

Commit 0879ef9

Browse files
committed
Fix failing tests
1 parent 484e484 commit 0879ef9

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

core/src/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct SessionConfig {
1515

1616
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
1717
#[serde(into = "&str")]
18-
#[serde(try_from = "&str")]
18+
#[serde(try_from = "String")]
1919
pub enum DeviceType {
2020
Unknown = 0,
2121
Computer = 1,
@@ -64,10 +64,10 @@ impl FromStr for DeviceType {
6464
}
6565
}
6666

67-
impl TryFrom<&str> for DeviceType {
67+
impl TryFrom<String> for DeviceType {
6868
type Error = &'static str;
6969

70-
fn try_from(value: &str) -> Result<Self, Self::Error> {
70+
fn try_from(value: String) -> Result<Self, Self::Error> {
7171
value.parse().map_err(|_| "Invalid device type")
7272
}
7373
}

discovery/src/response.rs

+43-22
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,64 @@ impl From<ParseError> for Error {
3333
mod status {
3434
use std::convert::TryFrom;
3535

36-
use serde::{Deserialize, Serialize, Serializer};
36+
use serde::de::IgnoredAny;
37+
use serde::{Deserialize, Serialize};
3738

3839
use super::{Error, SpotifyError};
3940

40-
fn serialize_status_code<S: Serializer>(code: &u32, serializer: S) -> Result<S::Ok, S::Error> {
41-
#[derive(Serialize)]
42-
#[serde(rename_all = "camelCase")]
43-
struct Repr {
44-
status: u32,
45-
status_string: &'static str,
41+
#[derive(Serialize)]
42+
#[serde(rename_all = "camelCase")]
43+
struct StatusSerialize {
44+
spotify_error: u32,
45+
status: u32,
46+
status_string: &'static str,
47+
}
48+
49+
impl From<Status> for StatusSerialize {
50+
fn from(st: Status) -> Self {
51+
let status_string = match &st.status {
52+
101 => "OK",
53+
301 => "ERROR-MISSING-ACTION",
54+
302 => "ERROR-INVALID-ACTION",
55+
303 => "ERROR-INVALID-ARGUMENTS",
56+
402 => "ERROR-SPOTIFY-ERROR",
57+
_ => "ERROR-UNKNOWN",
58+
};
59+
60+
Self {
61+
spotify_error: st.spotify_error,
62+
status: st.status,
63+
status_string,
64+
}
4665
}
66+
}
4767

48-
let status_string = match code {
49-
101 => "OK",
50-
301 => "ERROR-MISSING-ACTION",
51-
302 => "ERROR-INVALID-ACTION",
52-
303 => "ERROR-INVALID-ARGUMENTS",
53-
402 => "ERROR-SPOTIFY-ERROR",
54-
_ => "ERROR-UNKNOWN",
55-
};
68+
#[derive(Deserialize)]
69+
#[serde(rename_all = "camelCase")]
70+
struct StatusDeserialize {
71+
spotify_error: u32,
72+
status: u32,
73+
#[allow(dead_code)]
74+
status_string: IgnoredAny,
75+
}
5676

57-
Repr {
58-
status: *code,
59-
status_string,
77+
impl From<StatusDeserialize> for Status {
78+
fn from(st: StatusDeserialize) -> Self {
79+
Self {
80+
spotify_error: st.spotify_error,
81+
status: st.status,
82+
}
6083
}
61-
.serialize(serializer)
6284
}
6385

6486
/// Helper type to serialize a status. It must be imagined
6587
/// isomorphic to `Result<(), super::Error>`, and they are
6688
/// freely convertible.
6789
#[derive(Clone, Debug, Serialize, Deserialize)]
68-
#[serde(rename_all = "camelCase")]
90+
#[serde(into = "StatusSerialize", from = "StatusDeserialize")]
6991
pub struct Status {
70-
spotify_error: SpotifyError,
71-
#[serde(flatten, serialize_with = "serialize_status_code")]
7292
status: u32,
93+
spotify_error: SpotifyError,
7394
}
7495

7596
impl Status {

0 commit comments

Comments
 (0)