# BTreeSet/BTreeMap: Custom Ord

**URL:** <https://internals.rust-lang.org/t/btreeset-btreemap-custom-ord/8164>\
**Category:** libs\
**Created:** [August 9, 2018, 2:33pm UTC](https://internals.rust-lang.org/t/btreeset-btreemap-custom-ord/8164 "2018-08-09T14:33:43Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![elidupree](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/elidupree/32/4304_2.png) [@elidupree](https://internals.rust-lang.org/u/elidupree)\
**Post date:** [August 11, 2018, 10:34pm UTC](https://internals.rust-lang.org/t/btreeset-btreemap-custom-ord/8164/21 "2018-08-11T22:34:31Z")

</div>

I’ve used a newtype struct for this before. I found it reasonably convenient – packing and unpacking the struct at the boundary of the BTreeSet/Map was only a small amount of boilerplate.

For the general newtype pattern, there are still a few inconveniences. A lot of them would be taken care of if we had an easy way to delegate trait impls to the contained type, and a zero-cost way to coerce containers of the newtype to containers of the original struct (and vice versa). There was another thread a month ago that discussed some of this: [Revisit Orphan Rules](https://internals.rust-lang.org/t/revisit-orphan-rules/7795/89)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:30am UTC](https://internals.rust-lang.org/t/btreeset-btreemap-custom-ord/8164/22 "2019-03-25T08:30:40Z")

</div>

Closed on March 25, 2019, 8:30am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/btreeset-btreemap-custom-ord/8164.md?page=1)
