diff --git a/src/api/image_array/client.rs b/src/api/image_array/client.rs index 02784d8..515a113 100644 --- a/src/api/image_array/client.rs +++ b/src/api/image_array/client.rs @@ -3,7 +3,7 @@ use super::{ COLOUR_AXIS, IMAGE_BYTES_TYPE, }; use crate::api::TransmissionElementType; -use crate::client::{Response, ResponseTransaction, ResponseWithTransaction}; +use crate::client::{JsonResponse, Response, ResponseTransaction, ResponseWithTransaction}; use crate::{ASCOMError, ASCOMErrorCode, ASCOMResult}; use bytemuck::PodCastError; use mime::Mime; @@ -79,9 +79,7 @@ impl<'de> Visitor<'de> for ResponseVisitor { } } -struct JsonImageArray(ImageArray); - -impl<'de> Deserialize<'de> for JsonImageArray { +impl<'de> Deserialize<'de> for JsonResponse { fn deserialize>(deserializer: D) -> Result { deserializer.deserialize_map(ResponseVisitor).map(Self) } @@ -102,7 +100,7 @@ impl Response for ASCOMResult { fn from_reqwest(mime_type: Mime, bytes: &[u8]) -> eyre::Result> { if mime_type.essence_str() != IMAGE_BYTES_TYPE { - return >::from_reqwest(mime_type, bytes) + return >>::from_reqwest(mime_type, bytes) .map(|response| response.map(|response| response.map(|json| json.0))); } let metadata = bytes diff --git a/src/client/mod.rs b/src/client/mod.rs index 0aef559..e59d3d9 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -13,7 +13,7 @@ mod params; pub(crate) use params::{ActionParams, Method}; mod response; -pub(crate) use response::Response; +pub(crate) use response::{JsonResponse, Response}; use crate::api::{ConfiguredDevice, DevicePath, FallibleDeviceType, ServerInfo, TypedDevice}; use crate::response::ValueResponse; diff --git a/src/client/response.rs b/src/client/response.rs index 94ef415..64c63e0 100644 --- a/src/client/response.rs +++ b/src/client/response.rs @@ -34,7 +34,9 @@ pub(crate) trait Response: Sized { fn from_reqwest(mime_type: Mime, bytes: &[u8]) -> eyre::Result>; } -struct JsonResponse(T); +// This wrapper exists solely to work around Rust's lack of specialization (for now). +// It allows to implement traits that can't be implemented on e.g. `ASCOMResult` because `Result` is a built-in type. +pub(crate) struct JsonResponse(pub(crate) T); impl Response for JsonResponse { fn from_reqwest(mime_type: Mime, bytes: &[u8]) -> eyre::Result> {