blob: 1e10e35e3aeb193447c5e788fc91b356eb37df95 [file] [log] [blame] [view]
Allen George8b96bfb2016-11-02 08:01:08 -04001# Rust Thrift library
2
3## Overview
4
5This crate implements the components required to build a working Thrift server
6and client. It is divided into the following modules:
7
8 1. errors
9 2. protocol
10 3. transport
11 4. server
12 5. autogen
13
14The modules are layered as shown. The `generated` layer is code generated by the
15Thrift compiler's Rust plugin. It uses the components defined in this crate to
16serialize and deserialize types and implement RPC. Users interact with these
17types and services by writing their own code on top.
18
19 ```text
20 +-----------+
21 | app dev |
22 +-----------+
23 | generated | <-> errors/results
24 +-----------+
25 | protocol |
26 +-----------+
27 | transport |
28 +-----------+
29 ```
30
31## Using this crate
32
33Add `thrift = "x.y.z"` to your `Cargo.toml`, where `x.y.z` is the version of the
34Thrift compiler you're using.
35
36## API Documentation
37
38Full [Rustdoc](https://docs.rs/thrift/)
39
GREATEST Wiggler EvaR!b57d1262018-11-09 07:54:32 -050040## Compatibility
41
42The Rust library and auto-generated code targets Rust versions 1.28+.
43It does not currently use any Rust 2018 features.
44
45### Breaking Changes
46
47Breaking changes are minimized. When they are made they will be outlined below with transition guidelines.
48
Allen George2e90ef52021-03-01 14:47:04 -050049##### Thrift 0.15.0
50
51* **[THRIFT-5314]** - Generate enums implementations that are forward compatible (i.e. don't error on unknown values)
52
53 As a result of this change the Rust representation of an enum changes from a standard
54 Rust enum into a newtype struct with associated constants.
55
56 For example:
57
58 ```thrift
59 // THRIFT
60 enum Operation {
61 ADD,
62 SUBTRACT,
63 MULTIPLY,
64 DIVIDE,
65 }
66 ```
67
68 used to generate:
69
70 ```rust
71 // OLD AUTO-GENERATED RUST
72 pub enum Operation {
73 Add,
74 Subtract,
75 Multiply,
76 Divide,
77 }
78 ```
79
80 It *now* generates:
81
82 ```rust
83 // NEW AUTO-GENERATED RUST
84 pub struct Operation(pub i32);
85
86 impl Operation {
87 pub const ADD: Operation = Operation(0);
88 pub const SUBTRACT: Operation = Operation(1);
89 pub const MULTIPLY: Operation = Operation(2);
90 pub const DIVIDE: Operation = Operation(3);
91 }
92 ```
93
Allen Georgeb0d14132020-03-29 11:48:55 -040094##### Thrift 0.14.0
95
Allen George7ddbcc02020-11-08 09:51:19 -050096* **[THRIFT-5158]** - Rust library and generator now support Rust 2018 only. Required rust 1.40.0 or higher
Allen Georgeb0d14132020-03-29 11:48:55 -040097
98 The Rust `thrift` library was updated to Rust 2018 via `cargo fix --edition`.
99 All test code in the repo was updated as well. The code generator was also updated
100 to support Rust 2018 only.
101
Danny Browning181d9002019-04-15 09:50:24 -0600102##### Thrift 0.13.0
James E. King III057bebc2019-05-26 14:59:04 -0400103
Danny Browning181d9002019-04-15 09:50:24 -0600104* **[THRIFT-4536]** - Use TryFrom from std, required rust 1.34.0 or higher
105
106 Previously TryFrom was from try_from crate, it is now from the std library,
107 but this functionality is only available in rust 1.34.0. Additionally,
108 ordered-float is now re-exported under the thrift module to reduce
109 possible dependency mismatches.
110
GREATEST Wiggler EvaR!b57d1262018-11-09 07:54:32 -0500111##### Thrift 0.12.0
112
113* **[THRIFT-4529]** - Rust enum variants are now camel-cased instead of uppercased to conform to Rust naming conventions
114
115 Previously, enum variants were uppercased in the auto-generated code.
116 For example, the following thrift enum:
117
118 ```thrift
119 // THRIFT
120 enum Operation {
121 ADD,
122 SUBTRACT,
123 MULTIPLY,
124 DIVIDE,
125 }
126 ```
127
128 used to generate:
129
130 ```rust
131 // OLD AUTO-GENERATED RUST
132 pub enum Operation {
133 ADD,
134 SUBTRACT,
135 MULTIPLY,
136 DIVIDE,
137 }
138 ```
Allen George2e90ef52021-03-01 14:47:04 -0500139
GREATEST Wiggler EvaR!b57d1262018-11-09 07:54:32 -0500140 It *now* generates:
Allen George2e90ef52021-03-01 14:47:04 -0500141
GREATEST Wiggler EvaR!b57d1262018-11-09 07:54:32 -0500142 ```rust
143 // NEW AUTO-GENERATED RUST
144 pub enum Operation {
145 Add,
146 Subtract,
147 Multiply,
148 Divide,
149 }
150 ```
151
152 You will have to change all enum variants in your code to use camel-cased names.
153 This should be a search and replace.
154
Allen George8b96bfb2016-11-02 08:01:08 -0400155## Contributing
156
157Bug reports and PRs are always welcome! Please see the
158[Thrift website](https://thrift.apache.org/) for more details.
159
160Thrift Rust support requires code in several directories:
161
162* `compiler/cpp/src/thrift/generate/t_rs_generator.cc`: binding code generator
163* `lib/rs`: runtime library
164* `lib/rs/test`: supplemental tests
165* `tutorial/rs`: tutorial client and server
166* `test/rs`: cross-language test client and server
167
168All library code, test code and auto-generated code compiles and passes clippy
169without warnings. All new code must do the same! When making changes ensure that:
170
171* `rustc` does does output any warnings
172* `clippy` with default settings does not output any warnings (includes auto-generated code)
173* `cargo test` is successful
174* `make precross` and `make check` are successful
175* `tutorial/bin/tutorial_client` and `tutorial/bin/tutorial_server` communicate