Skip to content

Export BitVec so a key type can be declared outside the crate - #37

Closed
arthaud wants to merge 1 commit into
facebook:mainfrom
arthaud:export-bitvec
Closed

arthaud wants to merge 1 commit into
facebook:mainfrom
arthaud:export-bitvec

Conversation

@arthaud

@arthaud arthaud commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

The patricia tree containers are keyed by K: Into<BitVec>, and their iterators want K: From<&BitVec>. BitVec lives in a private module that datatype never re-exports, so no crate outside this one can write either impl: the bounds are satisfiable only by the integer types implemented here, and a caller keying on a newtype of its own has to fall back to HashMapAbstractEnvironment and give up the structural sharing that is the reason to reach for a patricia tree.

Re-export it, the way every other module in datatype is. Nothing else in bitvec is public, so this exports exactly the one type. Add to_int, the counterpart of from_int_with_len, without which From<&BitVec> can only be written a bit at a time while the conversions here reach for the private bits field; they now go through it instead. Add is_empty, which clippy asks for once the type is public.

Test plan: cargo test -- foreign_key_test.rs declares a key type the way a user of the library has to and exercises it against the map, the set and the environment. Note that main does not build: a30d887 calls update_node_by_key with an op taking its node by value, which b033084 had changed to take it by reference. This branch is based on main and was verified on b033084.

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 13, 2026
The patricia tree containers are keyed by `K: Into<BitVec>`, and their
iterators want `K: From<&BitVec>`. `BitVec` lives in a private module that
`datatype` never re-exports, so no crate outside this one can write either
impl: the bounds are satisfiable only by the integer types implemented here,
and a caller keying on a newtype of its own has to fall back to
`HashMapAbstractEnvironment` and give up the structural sharing that is the
reason to reach for a patricia tree.

Re-export it, the way every other module in `datatype` is. Nothing else in
`bitvec` is public, so this exports exactly the one type. Add `to_int`, the
counterpart of `from_int_with_len`, without which `From<&BitVec>` can only be
written a bit at a time while the conversions here reach for the private
`bits` field; they now go through it instead. Add `is_empty`, which clippy
asks for once the type is public.

Test plan: `cargo test` -- `foreign_key_test.rs` declares a key type the way a
user of the library has to and exercises it against the map, the set and the
environment. Note that `main` does not build: `a30d887` calls
`update_node_by_key` with an `op` taking its node by value, which `b033084`
had changed to take it by reference. This branch is based on `main` and was
verified on `b033084`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012HtCuENeDjeB74FUzn97FL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant