Brian Silverman | 7edd1ce | 2022-07-23 16:10:54 -0700 | [diff] [blame] | 1 | #include "aos/configuration_for_rust.h" |
| 2 | |
| 3 | #include "aos/for_rust.h" |
| 4 | |
| 5 | namespace aos::configuration { |
| 6 | |
| 7 | const Channel *GetChannelForRust(const Configuration *config, rust::Str name, |
| 8 | rust::Str type, rust::Str application_name, |
| 9 | const Node *node) { |
| 10 | return GetChannel(config, RustStrToStringView(name), |
| 11 | RustStrToStringView(type), |
| 12 | RustStrToStringView(application_name), node); |
| 13 | } |
| 14 | |
Brian Silverman | 67cdbd6 | 2022-08-15 06:03:55 -0700 | [diff] [blame] | 15 | const Node *GetNodeForRust(const Configuration *config, rust::Str name) { |
| 16 | return GetNode(config, RustStrToStringView(name)); |
| 17 | } |
| 18 | |
Brian Silverman | 7edd1ce | 2022-07-23 16:10:54 -0700 | [diff] [blame] | 19 | rust::Vec<uint8_t> MaybeReadConfigForRust( |
| 20 | rust::Str path, rust::Slice<const rust::Str> extra_import_paths) { |
| 21 | std::vector<std::string_view> cc_extra_import_paths; |
| 22 | for (const rust::Str &extra_import_path : extra_import_paths) { |
| 23 | cc_extra_import_paths.push_back(RustStrToStringView(extra_import_path)); |
| 24 | } |
Brian Silverman | 67cdbd6 | 2022-08-15 06:03:55 -0700 | [diff] [blame] | 25 | const auto cc_result = |
| 26 | MaybeReadConfig(RustStrToStringView(path), cc_extra_import_paths); |
Brian Silverman | 7edd1ce | 2022-07-23 16:10:54 -0700 | [diff] [blame] | 27 | rust::Vec<uint8_t> result; |
| 28 | if (cc_result) { |
| 29 | result.reserve(cc_result->span().size()); |
| 30 | for (uint8_t b : cc_result->span()) { |
| 31 | result.push_back(b); |
| 32 | } |
| 33 | } |
| 34 | return result; |
| 35 | } |
| 36 | |
| 37 | } // namespace aos::configuration |