Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support optional generation #7

Merged
merged 6 commits into from Apr 27, 2019
Merged

Support optional generation #7

merged 6 commits into from Apr 27, 2019

Conversation

ice1000
Copy link
Contributor

@ice1000 ice1000 commented Apr 19, 2019

Support generating only selected family of functions.

Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
@ice1000 ice1000 added the enhancement New feature or request label Apr 19, 2019
@ice1000 ice1000 requested a review from nrc April 19, 2019 04:36
Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
@ice1000
Copy link
Contributor Author

ice1000 commented Apr 19, 2019

This is required by tikv/raft-rs#218

@ice1000
Copy link
Contributor Author

ice1000 commented Apr 19, 2019

QAQ

pub enum GenOpt {
All,
NoImplMessage,
bitflags! {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt that whether we really need so many options or not. I only like MSG, CLR, HAS, and TKE in person. NEW can be replaced with Default, and GET, SET and MUT are useless because we can touch the internal fields directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The process of eliminating wrapper usages should be step by step and this (relatively) fine grained config can help us do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or can we merge these 3 as one option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hicqu I guess you've missed the point of this PR. What I was trying to do is to introduce a mechanism which can gradually reduce the wrapper functions. The ultimate goal is passing a GenOpt::empty() to the wrapper generator. Currently we're generating all of them so we can quickly launch prost support and my plan is to replace all usages of the generated wrappers with direct access. These options allow me to eliminate the generated wrappers step by step. That's all. 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So after all wrappers are removed, should we remove these options also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can! And I believe we're supposed to do so.

@hicqu
Copy link
Contributor

hicqu commented Apr 23, 2019

@nrc PTAL. kvproto is blocked on raft-rs, and raft-rs is blocked on here.

Copy link
Collaborator

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a few small comments inline

src/lib.rs Outdated Show resolved Hide resolved
src/wrapper.rs Show resolved Hide resolved
src/wrapper.rs Outdated Show resolved Hide resolved
src/wrapper.rs Outdated Show resolved Hide resolved
Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
@ice1000
Copy link
Contributor Author

ice1000 commented Apr 26, 2019

@nrc something else to consider:

We may need to provide an option that "generates getters that are not of primitive types".

@ice1000
Copy link
Contributor Author

ice1000 commented Apr 26, 2019

Because for non-primitive types, they become Option<Bla>, where we're supposed to provide a getter that uses a default value for them.

@ice1000
Copy link
Contributor Author

ice1000 commented Apr 26, 2019

I start doubting the idea of eliminating all getters. I'm here to propose another design of this library (unrelated to this PR):

  • Generate non-trivial getters (which unwrap_or_else for you)
  • Generate trivial getters with #[deprecated]
  • Provide options to eliminate deprecated stuffs

PTAL @nrc

Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
@nrc nrc merged commit 643897c into master Apr 27, 2019
@ice1000 ice1000 deleted the bitflags branch April 27, 2019 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants