Expose some Channel strings to Rust from C++ wrappers
I can't find a better way to do this, so it looks like we have to
manually wrap each of these with two C++ wrapper functions for now.
Change-Id: I3df44d99a7eae96e7eb41eb70e90737087c79c23
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
diff --git a/aos/configuration.rs b/aos/configuration.rs
index a264867..6711d77 100644
--- a/aos/configuration.rs
+++ b/aos/configuration.rs
@@ -2,7 +2,7 @@
use thiserror::Error;
-use aos_configuration_fbs::aos::Configuration as RustConfiguration;
+use aos_configuration_fbs::aos::{Channel as RustChannel, Configuration as RustConfiguration};
use aos_flatbuffers::{transmute_table_to, NonSizePrefixedFlatbuffer};
autocxx::include_cpp! (
@@ -20,6 +20,11 @@
generate!("aos::configuration::GetChannelForRust")
generate!("aos::configuration::GetNodeForRust")
+
+generate!("aos::configuration::HasChannelTypeForRust")
+generate!("aos::configuration::GetChannelTypeForRust")
+generate!("aos::configuration::HasChannelNameForRust")
+generate!("aos::configuration::GetChannelNameForRust")
);
#[cxx::bridge]
@@ -104,6 +109,28 @@
impl<'a, T: Into<&'a Configuration>> ConfigurationExt<'a> for T {}
+impl<'a> Into<&'a Channel> for RustChannel<'a> {
+ fn into(self) -> &'a Channel {
+ unsafe { transmute_table_to(&self._tab) }
+ }
+}
+
+pub trait ChannelExt<'a>: Into<&'a Channel> {
+ fn type_(self) -> Option<&'a str> {
+ let c = self.into();
+ ffi::aos::configuration::HasChannelTypeForRust(c)
+ .then(move || ffi::aos::configuration::GetChannelTypeForRust(c))
+ }
+
+ fn name(self) -> Option<&'a str> {
+ let c = self.into();
+ ffi::aos::configuration::HasChannelNameForRust(c)
+ .then(move || ffi::aos::configuration::GetChannelNameForRust(c))
+ }
+}
+
+impl<'a, T: Into<&'a Channel>> ChannelExt<'a> for T {}
+
/// # Panics
///
/// `path` must be valid UTF-8.