nv_redfish/protocol_features.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
16//! Redfish protocol features
17
18use crate::schema::redfish::service_root::Expand;
19use crate::schema::redfish::service_root::ProtocolFeaturesSupported;
20use std::convert::identity;
21
22/// Defines features supported by Redfish protocol. Provides helpers
23/// to write code that takes features in account.
24#[derive(Default)]
25pub struct ProtocolFeatures {
26 /// Expand query features support.
27 pub expand: ExpandQueryFeatures,
28}
29
30impl ProtocolFeatures {
31 /// Create protocol features from deserialized structure.
32 pub(crate) fn new(f: &ProtocolFeaturesSupported) -> Self {
33 Self {
34 expand: f
35 .expand_query
36 .as_ref()
37 .map(ExpandQueryFeatures::new)
38 .unwrap_or_default(),
39 }
40 }
41}
42
43/// Expand query support.
44pub struct ExpandQueryFeatures {
45 /// Indicates '*' support by the Server.
46 pub expand_all: bool,
47 /// Indicates '.' support by the Server.
48 pub no_links: bool,
49}
50
51// We want to have explicit defaults. Not language one. They are the
52// same by coincidence.
53#[allow(clippy::derivable_impls)]
54impl Default for ExpandQueryFeatures {
55 fn default() -> Self {
56 Self {
57 expand_all: false,
58 no_links: false,
59 }
60 }
61}
62
63impl ExpandQueryFeatures {
64 pub fn new(f: &Expand) -> Self {
65 Self {
66 expand_all: f.expand_all.is_some_and(identity),
67 no_links: f.no_links.is_some_and(identity),
68 }
69 }
70}