inline that one fixup method

This commit is contained in:
Erica Z 2024-11-01 09:59:32 +01:00
parent 9f97a2cae3
commit 6892f99070

View file

@ -7,15 +7,6 @@ fn runtime() -> &'static tokio::runtime::Runtime {
}) })
} }
impl<T> schema::SubsonicResponse<T> {
fn fixup(self) -> Result<T, Error> {
match self {
Self::Ok { inner } => Ok(inner),
Self::Failed { error } => Err(Error::SubsonicError(error)),
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
UrlParseError(url::ParseError), UrlParseError(url::ParseError),
@ -119,15 +110,19 @@ impl Client {
.expect("could not send subsonic response back to the main loop"); .expect("could not send subsonic response back to the main loop");
}); });
receiver let response = receiver
.recv() .recv()
.await .await
.expect("could not receive subsonic response from tokio")? .expect("could not receive subsonic response from tokio")?
.error_for_status()? .error_for_status()?
.json::<schema::SubsonicResponseOuter<T>>() .json::<schema::SubsonicResponseOuter<T>>()
.await? .await?
.subsonic_response .subsonic_response;
.fixup()
match response {
schema::SubsonicResponse::Ok { inner } => Ok(inner),
schema::SubsonicResponse::Failed { error } => Err(Error::SubsonicError(error)),
}
} }
pub async fn ping(&self) -> Result<(), Error> { pub async fn ping(&self) -> Result<(), Error> {