Skip to content

Add more Bson From<> implementations for better ergonomics. #130

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

Merged
merged 1 commit into from
Sep 19, 2019

Conversation

jcdyer
Copy link
Contributor

@jcdyer jcdyer commented Sep 17, 2019

This PR new From<> implementations to Bson to cover Vec<T>, &[T] objects, and &T (where T implements Into + Clone). Comparable impls exist in serde_json::Value, which is, I think, a good reference point for how the Bson type should operate. Having these impls in place eliminates a lot of manual cloning.

Caveat: When using this branch in the mongodb crate, there is one type inference break: Because the From<Array> implementation (== From<Vec<Bson>>) was replaced by From<Vec<T>> where T: Into<Bson>, Bson::from(Vec::new()) now complains that it needs to know the full type of Vec::new(). The problem is resolved by using Bson::Array(Vec::new()) instead of Bson::from. It also only shows up in case of a Vec of unspecified type, which means it should not affect conversion from a struct member in most cases. Again, this behavior is in line with how serde_json::Value operates.

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

Successfully merging this pull request may close these issues.

2 participants