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

Add i2u feature (#94) #95

Merged
merged 1 commit into from
Jul 4, 2018
Merged

Add i2u feature (#94) #95

merged 1 commit into from
Jul 4, 2018

Conversation

marcelbuesing
Copy link
Contributor

Basically as discussed in the issue this adds a feature flag for encoding unsigned types in signed types.
Open question: does this require further changes in the decoder. Given the tests it seems to work without changes in the decoder.
I also could not figure out how to conditionally add a test for the case that the "u2i" is not set. Hints welcome.

e.g.

// this should not run when the u2i feature is set
#[test]
fn uint64() {
    let obj_min: EncoderResult<Bson> = to_bson(&u64::MIN);
    assert_matches!(obj_min, Err(EncoderError::UnsupportedUnsignedType));
}

@zonyitoo
Copy link
Contributor

zonyitoo commented Jul 4, 2018

LGTM. cc @kyeah @saghm

@kyeah
Copy link
Contributor

kyeah commented Jul 4, 2018

Looks great, thank you!

Open question: does this require further changes in the decoder. Given the tests it seems to work without changes in the decoder.

unsigned integers will be stored as signed ints in the database, so they will be decoded as signed ints using the usual deserialize_iXX methods.

I also could not figure out how to conditionally add a test for the case that the "u2i" is not set. Hints welcome.

You should be able to create default test cases, and ignore it if the feature is enabled:

#[test]
#[cfg_attr(feature = "u2i", ignore)]

should be good to merge after that 👍

@marcelbuesing
Copy link
Contributor Author

marcelbuesing commented Jul 4, 2018

You should be able to create default test cases, and ignore it if the feature is enabled:

Thanks! Just added the missing tests.

@zonyitoo
Copy link
Contributor

zonyitoo commented Jul 4, 2018

@kyeah Merge it if you think it is Ok.

BTW. What if a crate uses bson with feature u2i, and the other crate in the same project doesn't?

@kyeah kyeah merged commit 4a19ba6 into mongodb:master Jul 4, 2018
@kyeah
Copy link
Contributor

kyeah commented Jul 4, 2018

Thanks @marcelbuesing!

What if a crate uses bson with feature u2i, and the other crate in the same project doesn't?

Not sure! I'm a little rusty on how dependency resolution works in rust :)

@zonyitoo
Copy link
Contributor

zonyitoo commented Jul 4, 2018

@marcelbuesing You can try this in your project, looking for feedbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants