-
Notifications
You must be signed in to change notification settings - Fork 178
RUST-740 Return Deserialize structs from list_databases and list_collections #328
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
RUST-740 Return Deserialize structs from list_databases and list_collections #328
Conversation
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.
Tagging in @kmahar for the public API changes.
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub struct IndexOptionDefaults { |
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.
This struct was missing a few attributes so I added them. I don't think any of our users will use this though.
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.
TIL create
accepts indexOptionDefaults
(I guess we do support it in Swift, so I knew this at some point, but we just take in a document so it was easier to forget about it than if it had a concrete type)
@@ -85,5 +85,4 @@ impl Operation for ListDatabases { | |||
#[derive(Debug, Deserialize)] | |||
struct ResponseBody { | |||
databases: Vec<Document>, | |||
total_size: Option<i64>, |
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.
This wasn't being used and in fact wasn't even being deserialized, since the server returned this value as a double until 5.0.
src/results.rs
Outdated
|
||
/// The amount of disk space in bytes that is consumed by the database. | ||
#[serde(deserialize_with = "crate::bson_util::deserialize_i64_from_bson_number")] | ||
pub size_on_disk: i64, |
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.
This value is returned as a bunch of different types depending on the server version, so we need a helper to deserialize it from whatever type to an integer. See here for an overview if interested.
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.
any reason for using an i64
here rather than a u64
?
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 agree u64 does seem to make sense for a size field
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 thought so too originally, but this is a value that's deserialized from server responses, meaning it can possibly have negative values. I checked elsewhere in the driver for precedent and saw that we use i64
for similar values, e.g. matched_count
in UpdateResult
. That being said, it seems like we probably would be totally fine using an unsigned value here if we wanted to, so I've updated it.
I also updated get_int
to be a little more lenient when reading integers from doubles in case of a floating point rounding issue.
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 filed RUST-764 to discuss updating other such fields.
pub collection_type: CollectionType, | ||
|
||
/// The options used to create the collection. | ||
pub options: CreateCollectionOptions, |
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 thought about creating a separate type for this in case they ever diverge (and also because it contains fields like write_concern
that don't make sense in this context), but the docs explicitly state that this field will contain the exact options provided to createCollection
, and looking through the server code confirms also this, so I figured this was pretty low risk. Let me know what you think.
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 agree it seems low risk
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.
sgtm
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub struct IndexOptionDefaults { |
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.
TIL create
accepts indexOptionDefaults
(I guess we do support it in Swift, so I knew this at some point, but we just take in a document so it was easier to forget about it than if it had a concrete type)
pub collection_type: CollectionType, | ||
|
||
/// The options used to create the collection. | ||
pub options: CreateCollectionOptions, |
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 agree it seems low risk
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.
LGTM mod Isabel's comment, I don't need to re-review
src/results.rs
Outdated
|
||
/// The amount of disk space in bytes that is consumed by the database. | ||
#[serde(deserialize_with = "crate::bson_util::deserialize_i64_from_bson_number")] | ||
pub size_on_disk: i64, |
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 agree u64 does seem to make sense for a size field
RUST-740
This PR updates
Client::list_databases
andDatabase::list_collections
to return structs that implementDeserialize
rather than justDocument
.