nv_redfish_core/deserialize.rs
1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use serde::Deserialize;
17use serde::Deserializer;
18
19/// Deserialize an optional nullable field. nv-redfish models these fields
20/// with `Option<Option<T>>`, where `None` means "no field" and
21/// `Some(None)` means the field is explicitly set to null.
22///
23/// # Errors
24///
25/// Returns an error if deserialization of the underlying type fails.
26pub fn de_optional_nullable<'de, D, T>(de: D) -> Result<Option<Option<T>>, D::Error>
27where
28 D: Deserializer<'de>,
29 T: Deserialize<'de>,
30{
31 Deserialize::deserialize(de).map(Some)
32}
33
34/// Deserialize a required nullable field. nv-redfish models these fields
35/// with `Option<T>`, where `None` means null.
36///
37/// # Errors
38///
39/// Returns an error if deserialization of the underlying type fails.
40pub fn de_required_nullable<'de, D, T>(de: D) -> Result<Option<T>, D::Error>
41where
42 D: Deserializer<'de>,
43 T: Deserialize<'de>,
44{
45 Deserialize::deserialize(de)
46}