phillipleblanc commented on issue #13753:
URL: https://github.com/apache/datafusion/issues/13753#issuecomment-2544328269

   I tried playing around with this in the Rust playground and wasn't able to 
get it to downcast properly: 
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=96cc916e29db395f4ec61374d9a2ce33
   
   ```rust
   use std::any::Any;
   
   trait UserDefinedLogicalNode: Any {
       fn as_any(&self) -> &dyn Any;
   }
   
   trait Unparseable: Any {
       fn as_any(&self) -> &dyn Any;
   }
   
   struct MyCustomNode {}
   
   impl UserDefinedLogicalNode for MyCustomNode {
       fn as_any(&self) -> &dyn Any { self }
   }
   
   impl Unparseable for MyCustomNode {
       fn as_any(&self) -> &dyn Any { self }
   }
   
   fn main() {
       let s = MyCustomNode {};
       let user_defined_local_node: &dyn UserDefinedLogicalNode = &s;
       
       // This fails to compile - "error[E0782]: expected a type, found a trait"
       // replacing with `.downcast_ref::<dyn Unparseable>()` fails to compile 
due to it being unsized
       // and replacing with `.downcast_ref::<&dyn Unparseable>()` compiles but 
doesn't work
       if let Some(_) = 
user_defined_local_node.as_any().downcast_ref::<Unparseable>() {
           println!("Downcast worked");
       } else {
           println!("Downcast didn't work")
       }
   }
   ```


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to