jiacai2050 commented on code in PR #1797:
URL: https://github.com/apache/fury/pull/1797#discussion_r1715524543


##########
rust/tests/tests/test_custom_trait.rs:
##########
@@ -0,0 +1,81 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fury_core::error::Error;
+use fury_core::fury::Fury;
+use fury_derive::{impl_polymorph, Fury};
+use std::any::{Any, TypeId};
+
+#[impl_polymorph]
+trait Animal {
+    fn get_name(&self) -> String;
+}
+
+#[derive(Fury, Debug)]
+#[polymorphic_traits("Animal")]

Review Comment:
   I think of one solution to this issue.
   
   Before this PR, `dyn Any` is already supported, so solution below should 
work? Let me know if there is anything I'm missing.
   
   > Suppose the trait already contains a `fn as_any(&self) -> &dyn Any` 
method, then we can use `trait_object.as_any().type_id()` to get underlying 
struct's type id, then we don't need this `polymorphic_traits`.
   
   `as_any` solution is a frequently used tricks in rust, so I think adding 
this requirement is an acceptable choice.
   



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