Skip to content

kv: remove Clone requirement for iterators, declutter lifetimes#209

Open
npry wants to merge 2 commits into
nrc/kvfrom
npry/kv.declutter
Open

kv: remove Clone requirement for iterators, declutter lifetimes#209
npry wants to merge 2 commits into
nrc/kvfrom
npry/kv.declutter

Conversation

@npry
Copy link
Copy Markdown
Collaborator

@npry npry commented May 27, 2026

Stacked on #208

Nerd-sniped me on the iterator requiring Clone (first commit), but in the course of that, I thought that the API (mostly in operations) could be simpler if the traits used associated types more rather than type params (second commit).

The first commit does the Clone bound on the iterator by doing much more exhaustive lifetime accounting — it separately tracks the 'store, 'guard, 'tx, and 'r (ref-to-txn-or-guard) lifetimes and imposes a strict containment in that order everywhere. This is overkill — the second commit rolls it back because the API changes obviate the need — but that lets the inner iterator be held for a much more specific lifetime and avoids the need to Clone.

The second commit is an observation mainly that you can get the Storage (and index base table) from the {Table,Index}Desc rather than passing it through everywhere in parallel by adjusting how the associated types work a bit and writing a trait to wrap Storage. There's a bit of a sacrifice in verbosity in getting some ATs back out (a lot of <Desc as TableDesc>::Key), but this removes the need for the 'a lifetime nearly everywhere and makes schema::GeneratedStorage mostly implicit. Most of this is just tracking that through and being more surgical with the lifetimes

Signed-off-by: Nathan Perry <nathan@tailscale.com>
Change-Id: I929c6926967b439649f78a1b46cb1cc06a6a6964
@npry npry changed the title Npry/kv.declutter kv: remove Clone requirement for iterators, declutter lifetimes May 27, 2026
Signed-off-by: Nathan Perry <nathan@tailscale.com>
Change-Id: I2c1b0aeb4941cc12038b3e2bea8719c06a6a6964
@npry npry force-pushed the npry/kv.declutter branch from 24d3507 to 393f86f Compare May 27, 2026 19:45
@npry npry marked this pull request as ready for review May 27, 2026 19:47
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.

1 participant