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)]
|
||||
/// struct Note {
|
||||
/// #[serde(deserialize_with = "deserialize_one")]
|
||||
/// to: Url
|
||||
/// to: [Url; 1]
|
||||
/// }
|
||||
///
|
||||
/// let note = serde_json::from_str::<Note>(r#"{"to": ["https://example.com/u/alice"] }"#);
|
||||
/// 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
|
||||
T: Deserialize<'de>,
|
||||
D: Deserializer<'de>,
|
||||
|
@ -75,8 +75,8 @@ where
|
|||
|
||||
let result: MaybeArray<T> = 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::<Note>(
|
||||
|
|
Loading…
Reference in a new issue