You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "stuartcarnie (via GitHub)" <gi...@apache.org> on 2023/03/20 22:51:24 UTC

[GitHub] [arrow-rs] stuartcarnie commented on a diff in pull request #3887: feat: Add Commands enum to decode prost messages to strong type

stuartcarnie commented on code in PR #3887:
URL: https://github.com/apache/arrow-rs/pull/3887#discussion_r1142749508


##########
arrow-flight/src/sql/mod.rs:
##########
@@ -71,22 +72,60 @@ pub trait ProstMessageExt: prost::Message + Default {
     fn as_any(&self) -> Any;
 }
 
+/// Macro to coerce a token to an item, specifically
+/// to build the `Commands` enum.
+///
+/// See: <https://danielkeep.github.io/tlborm/book/blk-ast-coercion.html>
+macro_rules! as_item {
+    ($i:item) => {
+        $i
+    };
+}
+
 macro_rules! prost_message_ext {
-    ($($name:ty,)*) => {
-        $(
-            impl ProstMessageExt for $name {
-                fn type_url() -> &'static str {
-                    concat!("type.googleapis.com/arrow.flight.protocol.sql.", stringify!($name))
+    ($($name:tt,)*) => {
+        paste! {
+            $(
+            const [<$name:snake:upper _TYPE_URL>]: &'static str = concat!("type.googleapis.com/arrow.flight.protocol.sql.", stringify!($name));
+            )*
+
+            as_item! {
+                pub enum Commands {

Review Comment:
   Good call – do you think adding some docs to the enum and then describing using the `TryFrom<Any>` trait to decoding them?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org