From ec97b44de47470f130f1314c03368e43cdb3a53d Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 5 Jan 2024 16:18:12 +0100 Subject: [PATCH] Fix return type for deserialize_one (#93) --- src/protocol/helpers.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/protocol/helpers.rs b/src/protocol/helpers.rs index 99ae7b2..8c69f65 100644 --- a/src/protocol/helpers.rs +++ b/src/protocol/helpers.rs @@ -56,12 +56,12 @@ where /// #[derive(serde::Deserialize)] /// struct Note { /// #[serde(deserialize_with = "deserialize_one")] -/// to: Url +/// to: [Url; 1] /// } /// /// let note = serde_json::from_str::(r#"{"to": ["https://example.com/u/alice"] }"#); /// assert!(note.is_ok()); -pub fn deserialize_one<'de, T, D>(deserializer: D) -> Result +pub fn deserialize_one<'de, T, D>(deserializer: D) -> Result<[T; 1], D::Error> where T: Deserialize<'de>, D: Deserializer<'de>, @@ -75,8 +75,8 @@ where let result: MaybeArray = Deserialize::deserialize(deserializer)?; Ok(match result { - MaybeArray::Simple(value) => value, - MaybeArray::Array([value]) => value, + MaybeArray::Simple(value) => [value], + MaybeArray::Array([value]) => [value], }) } @@ -125,7 +125,7 @@ mod tests { #[derive(serde::Deserialize)] struct Note { #[serde(deserialize_with = "deserialize_one")] - _to: Url, + _to: [Url; 1], } let note = serde_json::from_str::(