Fix return type for deserialize_one (#93)
This commit is contained in:
parent
3efa99514c
commit
ec97b44de4
1 changed files with 5 additions and 5 deletions
|
@ -56,12 +56,12 @@ where
|
||||||
/// #[derive(serde::Deserialize)]
|
/// #[derive(serde::Deserialize)]
|
||||||
/// struct Note {
|
/// struct Note {
|
||||||
/// #[serde(deserialize_with = "deserialize_one")]
|
/// #[serde(deserialize_with = "deserialize_one")]
|
||||||
/// to: Url
|
/// to: [Url; 1]
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let note = serde_json::from_str::<Note>(r#"{"to": ["https://example.com/u/alice"] }"#);
|
/// let note = serde_json::from_str::<Note>(r#"{"to": ["https://example.com/u/alice"] }"#);
|
||||||
/// assert!(note.is_ok());
|
/// assert!(note.is_ok());
|
||||||
pub fn deserialize_one<'de, T, D>(deserializer: D) -> Result<T, D::Error>
|
pub fn deserialize_one<'de, T, D>(deserializer: D) -> Result<[T; 1], D::Error>
|
||||||
where
|
where
|
||||||
T: Deserialize<'de>,
|
T: Deserialize<'de>,
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
|
@ -75,8 +75,8 @@ where
|
||||||
|
|
||||||
let result: MaybeArray<T> = Deserialize::deserialize(deserializer)?;
|
let result: MaybeArray<T> = Deserialize::deserialize(deserializer)?;
|
||||||
Ok(match result {
|
Ok(match result {
|
||||||
MaybeArray::Simple(value) => value,
|
MaybeArray::Simple(value) => [value],
|
||||||
MaybeArray::Array([value]) => value,
|
MaybeArray::Array([value]) => [value],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ mod tests {
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct Note {
|
struct Note {
|
||||||
#[serde(deserialize_with = "deserialize_one")]
|
#[serde(deserialize_with = "deserialize_one")]
|
||||||
_to: Url,
|
_to: [Url; 1],
|
||||||
}
|
}
|
||||||
|
|
||||||
let note = serde_json::from_str::<Note>(
|
let note = serde_json::from_str::<Note>(
|
||||||
|
|
Loading…
Reference in a new issue