You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jason Shui (Jira)" <ji...@apache.org> on 2021/01/20 13:18:00 UTC
[jira] [Updated] (THRIFT-5339) [Rust] Add `TObject` trait to cover
sync read & write methods of Struct/Union/Enum
[ https://issues.apache.org/jira/browse/THRIFT-5339?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jason Shui updated THRIFT-5339:
-------------------------------
Description:
Each Struct/Union/Enum generated by thrift-compiler will get two methods: `read_from_in_protocol` and `write_to_out_protocol`.
Firstly, I think these two methods are representing a certain ability of serialization, so they should be put in a trait;
Moreover, if this trait is provided, we can use trait bounding in out user codes, such as
```rust
// pseudo code
fn serialize_struct<T>(s: T) -> Vec<u8> where T: TObject {
s.write_to_out_protocol(protocol);
// do other things..
}
```
It could also be a pretty useful marker trait as you can see.
The name of `TObject` is only a superficial opinion, but I believe that there are enough reasons to make the trait.
was:TBD
> [Rust] Add `TObject` trait to cover sync read & write methods of Struct/Union/Enum
> ----------------------------------------------------------------------------------
>
> Key: THRIFT-5339
> URL: https://issues.apache.org/jira/browse/THRIFT-5339
> Project: Thrift
> Issue Type: New Feature
> Affects Versions: 0.13.0
> Reporter: Jason Shui
> Priority: Major
> Fix For: 0.14.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Each Struct/Union/Enum generated by thrift-compiler will get two methods: `read_from_in_protocol` and `write_to_out_protocol`.
> Firstly, I think these two methods are representing a certain ability of serialization, so they should be put in a trait;
> Moreover, if this trait is provided, we can use trait bounding in out user codes, such as
> ```rust
> // pseudo code
> fn serialize_struct<T>(s: T) -> Vec<u8> where T: TObject {
> s.write_to_out_protocol(protocol);
> // do other things..
> }
> ```
> It could also be a pretty useful marker trait as you can see.
> The name of `TObject` is only a superficial opinion, but I believe that there are enough reasons to make the trait.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)