-
Notifications
You must be signed in to change notification settings - Fork 28
generate options types from fdb.options #1
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
Conversation
|
This is awesome! I haven't even got a license up yet :) I was planning an Apache 2.0/MIT if that's ok with you, I'll add that to repo then we can merge that into this PR so that we have all that squared away.
Thanks, again for the PR. Let me get the LICENSE squared away, and then address the |
| extern crate inflector; | ||
| extern crate xml; | ||
| #[macro_use] | ||
| extern crate error_chain; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure is quite nice and simple. For the generator, you can get away with just using format_err! and returning the failure::Error type. in the result type, example:
fn example() -> Result<Type, failure::Error> {
Err(format_err!("my failure message: {}", extra_info)
}Can we switch to that instead? I believe most of Rust is going to be going in this direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to failure.
| } | ||
| } | ||
|
|
||
| pub enum ErrorPredicate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you look at error::FdbError in the foundationdb crate? We should maybe remove my hand-rolled version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced FdbErrorPredicate with options::ErrorPredicate. I'm not sure about name of fn code() -> fdb::FDBErrorPredicate. It's okay for other enum types which might have seperated value like String, but for ErrorPredicate case fn value() -> ... sounds better.
foundationdb/src/options.rs
Outdated
| impl ErrorPredicate { | ||
| pub fn code(&self) -> fdb::FDBErrorPredicate { | ||
| match *self { | ||
| ErrorPredicate::Retryable => 50000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically these values are fdb::FDBErrorPredicate_FDB_ERROR_PREDICATE_MAYBE_COMMITTED, rather than the raw value. Not sure if this is something the generator could write instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried to change those values to generated one, but there are some mismatches between names on fdb.options and names on fdb_c.h. Here's a list.
https://gist.github.com/yjh0502/cd19273e15464e5e2c377fc9f3ce3e03
- Some of them are just singular/plural problem, for example
WATCH/WATCHES,BYTE/BYTES. I can handle it with some brute-force replace rules. - It seems that options with
hidden=trueis not available on c header. I filtered those options. - There's one remaining non-regular case,
FDBMutationType_FDB_MUTATION_TYPE_SET_VERSIONSTAMPED_KEY, which should not be converted to..._KEYS. I just hard-coded the case :(
|
Thanks for the feedback!
For |
|
Thanks again for the PR, if this is ready I'll merge it in. I'm working on travis scripts right now, so we should get some testing options. |
|
Thanks again for the PR, this is a massive help! |
generate options types from fdb.options
error-chainfor error handling because I'm familiar with it. It might better to change it tofailure, as other sub-crates do.fdb.optionsfile into source. Please let me know if you have any preferred option.FdbScope::tyandFdbOption::tyreturnStringinstead of takingWrite(for maybeFormatter?) as a mutable argument. The code looks dirty but it works :(apply()function which call underlying C API for each enum types.