[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16683766#comment-16683766 ] ASF GitHub Bot commented on THRIFT-4529: jeking3 closed pull request #1625: THRIFT-4529: Rust enum variants are now camel-cased URL: https://github.com/apache/thrift/pull/1625 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/CHANGES b/CHANGES index 9533ad08f3..c24c2b2223 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,8 @@ Apache Thrift Changelog Breaking Changes since 0.11.0 [for 0.12.0]: - + +* [THRIFT-4529] - Rust enum variants are now camel-cased instead of uppercased to conform to Rust naming conventions * [THRIFT-4448] - Support for golang 1.6 and earlier has been dropped. * [THRIFT-4474] - PHP now uses the PSR-4 loader by default instead of class maps. * [THRIFT-4532] - method signatures changed in the compiler's t_oop_generator. diff --git a/compiler/cpp/src/thrift/generate/t_rs_generator.cc b/compiler/cpp/src/thrift/generate/t_rs_generator.cc index 5cd67f6755..ae30a35715 100644 --- a/compiler/cpp/src/thrift/generate/t_rs_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_rs_generator.cc @@ -499,6 +499,9 @@ class t_rs_generator : public t_generator { // the server half of a Thrift service. string rust_sync_processor_impl_name(t_service *tservice); + // Return the variant name for an enum variant + string rust_enum_variant_name(const string& name); + // Properly uppercase names for use in Rust. string rust_upper_case(const string& name); @@ -873,7 +876,7 @@ void t_rs_generator::render_enum_definition(t_enum* tenum, const string& enum_na render_rustdoc((t_doc*) val); f_gen_ << indent() - << uppercase(val->get_name()) + << rust_enum_variant_name(val->get_name()) << " = " << val->get_value() << "," @@ -934,7 +937,7 @@ void t_rs_generator::render_enum_conversion(t_enum* tenum, const string& enum_na f_gen_ << indent() << val->get_value() - << " => Ok(" << enum_name << "::" << uppercase(val->get_name()) << ")," + << " => Ok(" << enum_name << "::" << rust_enum_variant_name(val->get_name()) << ")," << endl; } f_gen_ << indent() << "_ => {" << endl; @@ -3254,6 +3257,23 @@ string t_rs_generator::rust_sync_processor_impl_name(t_service *tservice) { return "T" + rust_camel_case(tservice->get_name()) + "ProcessFunctions"; } +string t_rs_generator::rust_enum_variant_name(const string ) { + bool all_uppercase = true; + + for (size_t i = 0; i < name.size(); i++) { +if (isalnum(name[i]) && islower(name[i])) { + all_uppercase = false; + break; +} + } + + if (all_uppercase) { +return capitalize(camelcase(lowercase(name))); + } else { +return capitalize(camelcase(name)); + } +} + string t_rs_generator::rust_upper_case(const string& name) { string str(uppercase(underscore(name))); string_replace(str, "__", "_"); diff --git a/lib/rs/README.md b/lib/rs/README.md index 8b35eda95c..7c37a10bc6 100644 --- a/lib/rs/README.md +++ b/lib/rs/README.md @@ -37,6 +37,57 @@ Thrift compiler you're using. Full [Rustdoc](https://docs.rs/thrift/) +## Compatibility + +The Rust library and auto-generated code targets Rust versions 1.28+. +It does not currently use any Rust 2018 features. + +### Breaking Changes + +Breaking changes are minimized. When they are made they will be outlined below with transition guidelines. + +# Thrift 0.12.0 + +* **[THRIFT-4529]** - Rust enum variants are now camel-cased instead of uppercased to conform to Rust naming conventions + +Previously, enum variants were uppercased in the auto-generated code. +For example, the following thrift enum: + +```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 enum Operation { + Add, + Subtract, + Multiply, + Divide, + } +``` + +You will have to change all enum variants in your code to use camel-cased names. +This should be a search and replace. + ## Contributing Bug reports and PRs are always welcome! Please see the diff --git a/lib/rs/test/src/bin/kitchen_sink_server.rs
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16683662#comment-16683662 ] ASF GitHub Bot commented on THRIFT-4529: allengeorge commented on issue #1625: THRIFT-4529: Rust enum variants are now camel-cased URL: https://github.com/apache/thrift/pull/1625#issuecomment-437853453 @jeking3 I've made the requested changes, and, the only thing that fails in Travis is the SBCL build under autotools :/ Could this be merged please? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682943#comment-16682943 ] ASF GitHub Bot commented on THRIFT-4529: allengeorge edited a comment on issue #1625: THRIFT-4529: Rust enum variants are now camel-cased URL: https://github.com/apache/thrift/pull/1625#issuecomment-437686887 I've updated the `CHANGES` file, plus added a `Compatibility` section to the Rust `README` along with transition guidelines. I will do this in the future for any breaking changes. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682939#comment-16682939 ] ASF GitHub Bot commented on THRIFT-4529: allengeorge commented on issue #1625: THRIFT-4529: Rust enum variants are now camel-cased URL: https://github.com/apache/thrift/pull/1625#issuecomment-437686887 I've updated the `CHANGES` file, plus added a `COMPATIBILITY` section to the Rust `README` along with transition guidelines. I will do this in the future for any breaking changes. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682930#comment-16682930 ] ASF GitHub Bot commented on THRIFT-4529: allengeorge commented on issue #1625: THRIFT-4529: Camel-case Rust enum variants URL: https://github.com/apache/thrift/pull/1625#issuecomment-437685253 Yes - you're right: it is a breaking change. I'll make the README entries, and make sure I do so for any (hopefully rare!) breaking changes I make in the future. Thank you for catching this. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682921#comment-16682921 ] ASF GitHub Bot commented on THRIFT-4529: allengeorge commented on issue #1625: THRIFT-4529: Camel-case Rust enum variants URL: https://github.com/apache/thrift/pull/1625#issuecomment-437683052 I did not include a flag for backwards-compatibility. I'd prefer not to, because this change makes the autogenerated code conform to Rust naming conventions. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682917#comment-16682917 ] ASF GitHub Bot commented on THRIFT-4529: jeking3 commented on issue #1625: THRIFT-4529: Camel-case enum variants URL: https://github.com/apache/thrift/pull/1625#issuecomment-437681878 I assume the default setting is to use the previous way, and this is a new way, so it is backwards compatible? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
Re: [jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
Does this mean this is a breaking change? If you have to modify the cross tests... On Sun, Nov 11, 2018 at 10:35 AM ASF GitHub Bot (JIRA) wrote: > > [ > https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682909#comment-16682909 > ] > > ASF GitHub Bot commented on THRIFT-4529: > > > allengeorge commented on issue #1625: THRIFT-4529: Camel-case enum variants > URL: https://github.com/apache/thrift/pull/1625#issuecomment-437680138 > > >Build failure caused by a PEBCAK on my part (forgot to change enum > variant names in cross-tests). Fixing now. > > > This is an automated message from the Apache Git Service. > To respond to the message, please log on GitHub and use the > URL above to go to the specific comment. > > For queries about this service, please contact Infrastructure at: > us...@infra.apache.org > > > > Rust generation should include #![allow(non_snake_case)] or force > conform to Rust style guidelines > > > -- > > > > Key: THRIFT-4529 > > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > > Project: Thrift > > Issue Type: Improvement > > Components: Rust - Compiler > >Affects Versions: 0.11.0 > >Reporter: Joshua > >Assignee: Allen George > >Priority: Minor > > > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > > {code:sh} > > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > > {code} > > > > -- > This message was sent by Atlassian JIRA > (v7.6.3#76005) >
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682909#comment-16682909 ] ASF GitHub Bot commented on THRIFT-4529: allengeorge commented on issue #1625: THRIFT-4529: Camel-case enum variants URL: https://github.com/apache/thrift/pull/1625#issuecomment-437680138 Build failure caused by a PEBCAK on my part (forgot to change enum variant names in cross-tests). Fixing now. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682504#comment-16682504 ] ASF GitHub Bot commented on THRIFT-4529: allengeorge opened a new pull request #1625: THRIFT-4529: Camel-case enum variants URL: https://github.com/apache/thrift/pull/1625 Client: rs This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682477#comment-16682477 ] Allen George commented on THRIFT-4529: -- Humorously (I guess this is the story of all programming) this turns out to be more complicated than expected. There are a few cases: 1. All lowercase. "foo" => "Foo" 2. All uppercase. "FOO" => "Foo" 3. Screaming snake case (most common, I'd assume). "SCREAMING_SNAKE_CASE" => "ScreamingSnakeCase" 4. Snake case. "snake_case" => "SnakeCase" 4. Camel case. "CamelCase" => "CamelCase" The problem is, we have to figure out which one of the situations we're dealing with, because the conversions we'll perform will differ for every one, which is supremely annoying. I tried to avoid having to differentiate between the cases, but, the default implementations of {{t_generator::camelcase}} and {{t_generator::uppercase}} make this impossible. > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Assignee: Allen George >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16678115#comment-16678115 ] Allen George commented on THRIFT-4529: -- Looks like it. For some reason I totally missed the variant section in [Naming Conventions|https://doc.rust-lang.org/1.0.0/style/style/naming/README.html]. It looks like a very simple fix. > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16678114#comment-16678114 ] Allen George commented on THRIFT-4529: -- Looks like it. For some reason I totally missed the variant section in [Naming Conventions|https://doc.rust-lang.org/1.0.0/style/style/naming/README.html]. It looks like a very simple fix. > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (THRIFT-4529) Rust generation should include #![allow(non_snake_case)] or force conform to Rust style guidelines
[ https://issues.apache.org/jira/browse/THRIFT-4529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16678088#comment-16678088 ] Allen George commented on THRIFT-4529: -- I'm sorry I missed this :/ Does this happen only for enum variants? > Rust generation should include #![allow(non_snake_case)] or force conform to > Rust style guidelines > -- > > Key: THRIFT-4529 > URL: https://issues.apache.org/jira/browse/THRIFT-4529 > Project: Thrift > Issue Type: Improvement > Components: Rust - Compiler >Affects Versions: 0.11.0 >Reporter: Joshua >Priority: Minor > > Without this, building a project using a thrift file meant for multiple > languages may end up with many compiler warnings similar to the following: > {code:sh} > warning: variant `EXAMPLE_NAME` should have a camel case name such as > `ExampleName` > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)