thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
325 stars 40 forks source link

Use DeserializeOwned on model bounds. #35

Closed thedodd closed 4 years ago

thedodd commented 5 years ago

This will do away with the lifetime bounds which are currently associated with model instances.

thedodd commented 5 years ago

This may actually conflict with #37.

thedodd commented 5 years ago

@magiclen per some of the other issues you've opened here, I wanted to include you here.

I've been leaning towards using the DeserializeOwned bound on these models, and given the nature of a data model, I'm inclined to say that it should not be generic. Instead ... perhaps if you need a generic model, instead of using generics, you could use a bson field type. That would allow you to use the same model, and then just deserialize the field type as needed. You could even use an enum type with serde's internally tagged serialization model, which would remove the need for generic types.

As far as generic lifetime bounds ... well, when taking data directly out of the database, it doesn't make much sense. I am inclined to keep generic types & lifetimes out of the models in order to keep them simple and direct.

Thoughts?