oxidecomputer / oxidecomputer/hubris

want a way to have `counters` derive counters for newtypes around integers with "reasonable" max values

Open
#2,675 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

:wave: good first issue developer-experience
Dominant language
Rust
Stars
3.6k
Forks
239
Avg merge
1d 12h
Merged PRs (30d)
23

Description

See this comment I left on #2668

this is cute; I wonder if we might want the counters crate to have a macro or something for saying "yes, this looks like a u32, but it will always be in some range, so you can derive counters for it without having to worry"; elsewhere, I've tended to just use repr(N) enums for this sort of thing, like this thing:
https://github.com/oxidecomputer/hubris/blob/0d1ba0453a5d80470f07ea9949eb82bc3c291e01/drv/psc-seq-server/src/main.rs#L390-L403
but that then requires some weirdish boilerplate for converting between the enum and integers if you also want to index arrays or whatever.

very much not a blocker for this PR, but I wonder if we might throw together a little newtype-integer-counter derive or something that works like this.

Originally posted by @hawkw in https://github.com/oxidecomputer/hubris/pull/2668#discussion_r3937999238

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the counters crate and the discussion in issue #2668. Review the linked Hubris example in drv/psc-seq-server/src/main.rs around lines 390-403 to understand the existing repr(N) enum approach. Define the desired newtype-integer-counter behavior and how its max range should be specified before identifying the implementation and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.