Skip to main content

nv_redfish/
mac_address.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026 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 std::fmt;
17
18/// MAC address returned by the crate.
19///
20/// nv-redfish is not opionated about format of the MAC addresses. So,
21/// it returns whatever server returns. This type is only introduced
22/// to reduce number of untyped &str returned by functions.
23#[derive(Clone, Copy, Debug)]
24#[repr(transparent)]
25pub struct MacAddress<'a>(&'a str);
26
27impl MacAddress<'_> {
28    /// Create new MAC-address.
29    #[must_use]
30    pub const fn new(v: &str) -> MacAddress<'_> {
31        MacAddress(v)
32    }
33
34    /// String representation MAC-address.
35    #[must_use]
36    pub const fn as_str(&self) -> &str {
37        self.0
38    }
39}
40
41impl fmt::Display for MacAddress<'_> {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        self.0.fmt(f)
44    }
45}