summaryrefslogtreecommitdiff
path: root/lib/rs
diff options
context:
space:
mode:
authorAllen George <allengeorge@apache.org>2021-03-01 14:47:04 -0500
committerGitHub <noreply@github.com>2021-03-01 14:47:04 -0500
commit2e90ef569c1b38f6e0f1279e3f25d2a7f6b5ff99 (patch)
tree21744c04e50cf73a19ce2e9b858d65409d5501af /lib/rs
parent4f6439b30953865fd1ec23729cbf17292c0ad17d (diff)
downloadthrift-2e90ef569c1b38f6e0f1279e3f25d2a7f6b5ff99.tar.gz
[THRIFT-5314][THRIFT-4101] Generate enums that don't error on unexpected values (#2337)
Client: rs
Diffstat (limited to 'lib/rs')
-rw-r--r--lib/rs/README.md47
-rw-r--r--lib/rs/test/src/bin/kitchen_sink_server.rs6
2 files changed, 50 insertions, 3 deletions
diff --git a/lib/rs/README.md b/lib/rs/README.md
index 555d219d2..1e10e35e3 100644
--- a/lib/rs/README.md
+++ b/lib/rs/README.md
@@ -46,6 +46,51 @@ It does not currently use any Rust 2018 features.
Breaking changes are minimized. When they are made they will be outlined below with transition guidelines.
+##### Thrift 0.15.0
+
+* **[THRIFT-5314]** - Generate enums implementations that are forward compatible (i.e. don't error on unknown values)
+
+ As a result of this change the Rust representation of an enum changes from a standard
+ Rust enum into a newtype struct with associated constants.
+
+ For example:
+
+ ```thrift
+ // THRIFT
+ enum Operation {
+ ADD,
+ SUBTRACT,
+ MULTIPLY,
+ DIVIDE,
+ }
+ ```
+
+ used to generate:
+
+ ```rust
+ // OLD AUTO-GENERATED RUST
+ pub enum Operation {
+ Add,
+ Subtract,
+ Multiply,
+ Divide,
+ }
+ ```
+
+ It *now* generates:
+
+ ```rust
+ // NEW AUTO-GENERATED RUST
+ pub struct Operation(pub i32);
+
+ impl Operation {
+ pub const ADD: Operation = Operation(0);
+ pub const SUBTRACT: Operation = Operation(1);
+ pub const MULTIPLY: Operation = Operation(2);
+ pub const DIVIDE: Operation = Operation(3);
+ }
+ ```
+
##### Thrift 0.14.0
* **[THRIFT-5158]** - Rust library and generator now support Rust 2018 only. Required rust 1.40.0 or higher
@@ -91,7 +136,9 @@ Breaking changes are minimized. When they are made they will be outlined below w
DIVIDE,
}
```
+
It *now* generates:
+
```rust
// NEW AUTO-GENERATED RUST
pub enum Operation {
diff --git a/lib/rs/test/src/bin/kitchen_sink_server.rs b/lib/rs/test/src/bin/kitchen_sink_server.rs
index 6df39e4bc..8b910b3bf 100644
--- a/lib/rs/test/src/bin/kitchen_sink_server.rs
+++ b/lib/rs/test/src/bin/kitchen_sink_server.rs
@@ -209,12 +209,12 @@ struct FullHandler;
impl FullMealAndDrinksServiceSyncHandler for FullHandler {
fn handle_full_meal_and_drinks(&self) -> thrift::Result<FullMealAndDrinks> {
println!("full_meal_and_drinks: handling full meal and drinks call");
- Ok(FullMealAndDrinks::new(full_meal(), Drink::CanadianWhisky))
+ Ok(FullMealAndDrinks::new(full_meal(), Drink::CANADIAN_WHISKY))
}
fn handle_best_pie(&self) -> thrift::Result<Pie> {
println!("full_meal_and_drinks: handling pie call");
- Ok(Pie::MississippiMud) // I prefer Pie::Pumpkin, but I have to check that casing works
+ Ok(Pie::MISSISSIPPI_MUD) // I prefer Pie::Pumpkin, but I have to check that casing works
}
}
@@ -259,7 +259,7 @@ fn noodle() -> Noodle {
}
fn ramen() -> Ramen {
- Ramen::new("Mr Ramen".to_owned(), 72, BrothType::Miso)
+ Ramen::new("Mr Ramen".to_owned(), 72, BrothType::MISO)
}
fn napkin() -> Napkin {