Skip to main content

driver_manager_types/
conversions.rs

1// Copyright 2026 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 as fdf;
6
7// Note: We use `to_...` functions instead of implementing `Into` or `From` traits
8// because of Rust's orphan rule. Since `fdf` types are not defined in the current crate,
9// we cannot implement foreign traits for foreign types. A newtype wrapper could be used to
10// work around this, but simple conversion functions suffice for now.
11
12pub fn to_property2(property: &fdf::NodeProperty) -> fdf::NodeProperty2 {
13    let key = match &property.key {
14        fdf::NodePropertyKey::StringValue(s) => s.clone(),
15        _ => panic!("Integer keys are deprecated"),
16    };
17    fdf::NodeProperty2 { key, value: property.value.clone() }
18}
19
20pub fn to_deprecated_property(property: &fdf::NodeProperty2) -> fdf::NodeProperty {
21    fdf::NodeProperty {
22        key: fdf::NodePropertyKey::StringValue(property.key.clone()),
23        value: property.value.clone(),
24    }
25}
26
27pub fn to_bind_rule2(bind_rule: &fdf::BindRule) -> fdf::BindRule2 {
28    let key = match &bind_rule.key {
29        fdf::NodePropertyKey::StringValue(s) => s.clone(),
30        _ => panic!("Integer keys are deprecated"),
31    };
32    fdf::BindRule2 { key, condition: bind_rule.condition, values: bind_rule.values.clone() }
33}