theweipeng opened a new pull request, #1797:
URL: https://github.com/apache/fury/pull/1797

   ## What does this PR do?
   ### Support serialization and deserialization of trait objects
   The relationship between a trait object and a concrete type is generated by 
a macro and stored in a Fury instance. We can access the serializer and 
deserializer using the  `Fury type ID`  and  `Rust type ID`.
   
   Use as follows
   ```Rust
       #[impl_polymorph]
       trait Animal {
           fn get_name(&self) -> String;
       }
   
       #[derive(Fury, Debug)]
       #[polymorphic_traits("Animal")]
       struct Dog {
           name: String
       }
   
       impl Animal for Dog {
           fn get_name(&self) -> String {
               self.name.clone()
           }
       }
   
       #[derive(Fury)]
       struct Person {
           pet: Box<dyn Animal>
       }
   
       let p = Person {
           pet: Box::new(Dog {
               name: String::from("puppy")
           })
       };
       let mut fury = Fury::default();
   
       fury.register::<Person>(501);
       fury.register::<Dog>(500);
       let bin = fury.serialize(&p);
       let obj: Person = fury.deserialize(&bin).unwrap();
       assert_eq!(obj.pet.get_name(), "puppy");
   ```
   We should add `impl_polymorph` for trait  which is use for serializing 
`Box<dyn xxxx>`  and `polymorphic_traits` for struct which is use for generate 
code to cast upcast concete type to trait object. Note that rust not support 
upcast trait yet(https://github.com/rust-lang/rust/issues/65991).


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