fdf_component/node/
properties.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fidl_fuchsia_driver_framework::NodePropertyValue;
6
7/// A newtype wrapper that can be used to construct [`NodePropertyValue`]-compatible values
8/// for [`crate::NodeBuilder::add_property`]
9pub struct PropertyValue(pub(crate) NodePropertyValue);
10
11impl From<String> for PropertyValue {
12    fn from(value: String) -> Self {
13        Self(NodePropertyValue::StringValue(value))
14    }
15}
16
17impl From<&str> for PropertyValue {
18    fn from(value: &str) -> Self {
19        Self(NodePropertyValue::StringValue(value.to_owned()))
20    }
21}
22
23impl From<u32> for PropertyValue {
24    fn from(value: u32) -> Self {
25        Self(NodePropertyValue::IntValue(value))
26    }
27}
28
29impl From<bool> for PropertyValue {
30    fn from(value: bool) -> Self {
31        Self(NodePropertyValue::BoolValue(value))
32    }
33}
34
35impl PropertyValue {
36    /// Creates a value from something that is string-like
37    pub fn from_string(value: impl Into<String>) -> Self {
38        String::into(value.into())
39    }
40
41    /// Creates a value from something that is integer-like
42    pub fn from_int(value: impl Into<u32>) -> Self {
43        u32::into(value.into())
44    }
45
46    /// Creates a value from something that is bool-like
47    pub fn from_bool(value: impl Into<bool>) -> Self {
48        bool::into(value.into())
49    }
50}