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.
diff --git a/aos/configuration_for_rust.h b/aos/configuration_for_rust.h
index 9bf9c75..c01ef57 100644
--- a/aos/configuration_for_rust.h
+++ b/aos/configuration_for_rust.h
@@ -1,7 +1,10 @@
 #ifndef AOS_CONFIGURATION_FOR_RUST_H_
 #define AOS_CONFIGURATION_FOR_RUST_H_
 
+#include <optional>
+
 #include "aos/configuration.h"
+#include "aos/for_rust.h"
 #include "cxx.h"
 
 namespace aos::configuration {
@@ -18,6 +21,20 @@
 rust::Vec<uint8_t> MaybeReadConfigForRust(
     rust::Str path, rust::Slice<const rust::Str> extra_import_paths);
 
+inline bool HasChannelTypeForRust(const Channel &channel) {
+  return channel.type();
+}
+inline rust::Str GetChannelTypeForRust(const Channel &channel) {
+  return StringViewToRustStr(channel.type()->string_view());
+}
+
+inline bool HasChannelNameForRust(const Channel &channel) {
+  return channel.name();
+}
+inline rust::Str GetChannelNameForRust(const Channel &channel) {
+  return StringViewToRustStr(channel.name()->string_view());
+}
+
 }  // namespace aos::configuration
 
 #endif  // AOS_CONFIGURATION_FOR_RUST_H_