ruma_common/serde/
single_element_seq.rs

1//! De-/serialization functions to and from single element sequences.
2
3use serde::{
4    de::{Deserialize, Deserializer},
5    ser::{Serialize, Serializer},
6};
7
8/// Serialize the given value as a list of just that value.
9pub fn serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
10where
11    T: Serialize,
12    S: Serializer,
13{
14    [value].serialize(serializer)
15}
16
17/// Deserialize a list of one item and return that item.
18pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
19where
20    T: Deserialize<'de>,
21    D: Deserializer<'de>,
22{
23    <[_; 1]>::deserialize(deserializer).map(|[first]| first)
24}