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

Revisions don't compare as numbers #16

Closed
cmbrandenburg opened this issue Dec 31, 2015 · 1 comment
Closed

Revisions don't compare as numbers #16

cmbrandenburg opened this issue Dec 31, 2015 · 1 comment
Assignees
Milestone

Comments

@cmbrandenburg
Copy link
Member

CouchDB revisions comprise a number followed by a hash value. A revision with a smaller number is less than a revision with a bigger number.

However, the Revision type compares the number parts lexicographically. E.g., 7 should be less than 13, but the Revision type orders 13 before 7 because the character '1' is less than the character '7'.

The following program demonstrates the problem by failing the assertion:

let r1 = couchdb::Revision::from("7-12345678123456781234567812345678");
let r2 = couchdb::Revision::from("13-12345678123456781234567812345678");
assert!(r1 < r2);
@cmbrandenburg cmbrandenburg self-assigned this Dec 31, 2015
@cmbrandenburg cmbrandenburg added this to the v0.4.0 milestone Dec 31, 2015
@cmbrandenburg
Copy link
Member Author

As of v0.3.x, the API exposed by the Revision type is fundamentally flawed. The type thinly wraps a String by implementing traits such as AsRef<&str>, From<String>, etc., but, conceptually, the Revision type should instead wrap a tuple comprising the number part (of u64 type) and the hash part (of a string or binary type). So, for example, the type should not implement the AsRef<&str> or From<String> traits but should instead implement std::str::FromStr.

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

No branches or pull requests

1 participant