Skip to content

Implement Ord for BinarySubtype - #635

Merged
abr-egn merged 3 commits into
mongodb:mainfrom
tyilo:binary-subtype-ord
Jan 12, 2026
Merged

Implement Ord for BinarySubtype#635
abr-egn merged 3 commits into
mongodb:mainfrom
tyilo:binary-subtype-ord

Conversation

@tyilo

@tyilo tyilo commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

I have the following type in my code that I would like to store in a BTreeMap:

enum BsonType {
    Double,
    String,
    Document,
    Array,
    Binary(BinarySubtype),
    Undefined,
    ObjectId,
    Boolean,
    DateTime,
    Null,
    RegularExpression,
    DbPointer,
    JavaScriptCode,
    Symbol,
    JavaScriptCodeWithScope,
    Int32,
    Timestamp,
    Int64,
    Decimal128,
    MinKey,
    MaxKey,
}

So I need to implement Ord for it. This is easier to do with this change.

@tyilo
tyilo requested a review from a team as a code owner January 8, 2026 15:02
@tyilo
tyilo requested a review from abr-egn January 8, 2026 15:02
@tyilo
tyilo marked this pull request as draft January 8, 2026 16:01
@tyilo

tyilo commented Jan 8, 2026

Copy link
Copy Markdown
Contributor Author

I don't think this works because UserDefined(123) != Reserved(123), but the compare equal with this Ord impl.

@tyilo
tyilo marked this pull request as ready for review January 9, 2026 11:41
@tyilo

tyilo commented Jan 9, 2026

Copy link
Copy Markdown
Contributor Author

I don't think this works because UserDefined(123) != Reserved(123), but the compare equal with this Ord impl.

I changed the PartialEq and Hash implementation so that Generic == UserDefined(0x00) == Reserved(0x00).

@abr-egn

abr-egn commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Seems reasonable enough to me.

Out of curiosity, your enum looks equivalent to ElementType except for the additional BinarySubtype value; can you share your use case for carrying the subtype along with that?

@tyilo

tyilo commented Jan 12, 2026

Copy link
Copy Markdown
Contributor Author

Out of curiosity, your enum looks equivalent to ElementType except for the additional BinarySubtype value; can you share your use case for carrying the subtype along with that?

I use it to generate a schema from the documents in a MongoDB collection. I need the binary subtype to see if it is an UUID.

@abr-egn
abr-egn merged commit 3d230ba into mongodb:main Jan 12, 2026
12 checks passed
@tyilo
tyilo deleted the binary-subtype-ord branch January 12, 2026 12:14
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