stuartcarnie commented on code in PR #3887:
URL: https://github.com/apache/arrow-rs/pull/3887#discussion_r1142905798
##########
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 {
+ $($name($name),)*
}
+ }
- fn as_any(&self) -> Any {
- Any {
- type_url: <$name>::type_url().to_string(),
- value: self.encode_to_vec().into(),
+ impl Commands {
+ pub fn unpack(any: Any) -> Result<Commands, ArrowError> {
Review Comment:
Agreed – I've removed unpack completely, as `Command::try_from` or
`any.try_into()` is much better 👍🏻
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]