mwapi_responses/timestamp.rs
1/*
2Copyright (C) 2021 Kunal Mehta <legoktm@debian.org>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 3 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18use mwtimestamp::Timestamp;
19use serde::de::IntoDeserializer;
20use serde::{de, Deserialize};
21
22/// Not public, for internal use only.
23///
24/// Wrapper for notificationtimestamp which is Option<Timestamp>
25/// except uses empty string for the none case
26#[doc(hidden)]
27pub fn deserialize_notificationtimestamp<'de, D>(
28 deserializer: D,
29) -> Result<Option<Timestamp>, D::Error>
30where
31 D: de::Deserializer<'de>,
32{
33 let opt = Option::<String>::deserialize(deserializer)?;
34 let opt = opt.as_deref();
35 match opt {
36 None | Some("") => Ok(None),
37 Some(s) => Timestamp::deserialize(s.into_deserializer()).map(Some),
38 }
39}