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.
45use fidl_fuchsia_driver_framework::{NodePropertyKey, NodePropertyValue};
67/// A newtype wrapper that can be used to construct [`NodePropertyKey`]-compatible values
8/// for [`crate::NodeBuilder::add_property`]
9pub struct PropertyKey(pub(crate) NodePropertyKey);
1011impl From<String> for PropertyKey {
12fn from(value: String) -> Self {
13Self(NodePropertyKey::StringValue(value))
14 }
15}
1617impl From<&str> for PropertyKey {
18fn from(value: &str) -> Self {
19Self(NodePropertyKey::StringValue(value.to_owned()))
20 }
21}
2223impl From<u32> for PropertyKey {
24fn from(value: u32) -> Self {
25Self(NodePropertyKey::IntValue(value))
26 }
27}
2829impl PropertyKey {
30/// Creates a key from something that is string-like
31pub fn from_string(value: impl Into<String>) -> Self {
32 String::into(value.into())
33 }
3435/// Creates a key from something that is integer-like
36pub fn from_int(value: impl Into<u32>) -> Self {
37 u32::into(value.into())
38 }
39}
4041/// A newtype wrapper that can be used to construct [`NodePropertyValue`]-compatible values
42/// for [`crate::NodeBuilder::add_property`]
43pub struct PropertyValue(pub(crate) NodePropertyValue);
4445impl From<String> for PropertyValue {
46fn from(value: String) -> Self {
47Self(NodePropertyValue::StringValue(value))
48 }
49}
5051impl From<&str> for PropertyValue {
52fn from(value: &str) -> Self {
53Self(NodePropertyValue::StringValue(value.to_owned()))
54 }
55}
5657impl From<u32> for PropertyValue {
58fn from(value: u32) -> Self {
59Self(NodePropertyValue::IntValue(value))
60 }
61}
6263impl From<bool> for PropertyValue {
64fn from(value: bool) -> Self {
65Self(NodePropertyValue::BoolValue(value))
66 }
67}
6869impl PropertyValue {
70/// Creates a value from something that is string-like
71pub fn from_string(value: impl Into<String>) -> Self {
72 String::into(value.into())
73 }
7475/// Creates a value from something that is integer-like
76pub fn from_int(value: impl Into<u32>) -> Self {
77 u32::into(value.into())
78 }
7980/// Creates a value from something that is bool-like
81pub fn from_bool(value: impl Into<bool>) -> Self {
82 bool::into(value.into())
83 }
84}