| Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 1 | # Rust Thrift library |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | This crate implements the components required to build a working Thrift server |
| 6 | and 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 | |
| 14 | The modules are layered as shown. The `generated` layer is code generated by the |
| 15 | Thrift compiler's Rust plugin. It uses the components defined in this crate to |
| 16 | serialize and deserialize types and implement RPC. Users interact with these |
| 17 | types 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 | |
| 33 | Add `thrift = "x.y.z"` to your `Cargo.toml`, where `x.y.z` is the version of the |
| 34 | Thrift compiler you're using. |
| 35 | |
| 36 | ## API Documentation |
| 37 | |
| 38 | Full [Rustdoc](https://docs.rs/thrift/) |
| 39 | |
| GREATEST Wiggler EvaR! | b57d126 | 2018-11-09 07:54:32 -0500 | [diff] [blame] | 40 | ## Compatibility |
| 41 | |
| 42 | The Rust library and auto-generated code targets Rust versions 1.28+. |
| 43 | It does not currently use any Rust 2018 features. |
| 44 | |
| 45 | ### Breaking Changes |
| 46 | |
| 47 | Breaking changes are minimized. When they are made they will be outlined below with transition guidelines. |
| 48 | |
| Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame^] | 49 | ##### 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 George | b0d1413 | 2020-03-29 11:48:55 -0400 | [diff] [blame] | 94 | ##### Thrift 0.14.0 |
| 95 | |
| Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 96 | * **[THRIFT-5158]** - Rust library and generator now support Rust 2018 only. Required rust 1.40.0 or higher |
| Allen George | b0d1413 | 2020-03-29 11:48:55 -0400 | [diff] [blame] | 97 | |
| 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 Browning | 181d900 | 2019-04-15 09:50:24 -0600 | [diff] [blame] | 102 | ##### Thrift 0.13.0 |
| James E. King III | 057bebc | 2019-05-26 14:59:04 -0400 | [diff] [blame] | 103 | |
| Danny Browning | 181d900 | 2019-04-15 09:50:24 -0600 | [diff] [blame] | 104 | * **[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! | b57d126 | 2018-11-09 07:54:32 -0500 | [diff] [blame] | 111 | ##### 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 George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame^] | 139 | |
| GREATEST Wiggler EvaR! | b57d126 | 2018-11-09 07:54:32 -0500 | [diff] [blame] | 140 | It *now* generates: |
| Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame^] | 141 | |
| GREATEST Wiggler EvaR! | b57d126 | 2018-11-09 07:54:32 -0500 | [diff] [blame] | 142 | ```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 George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 155 | ## Contributing |
| 156 | |
| 157 | Bug reports and PRs are always welcome! Please see the |
| 158 | [Thrift website](https://thrift.apache.org/) for more details. |
| 159 | |
| 160 | Thrift 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 | |
| 168 | All library code, test code and auto-generated code compiles and passes clippy |
| 169 | without 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 |