Skip to content

add enum type parameter to Field to prevent read_as_enum() mismatch - #102

Draft
nataliepopescu wants to merge 1 commit into
tock:mainfrom
nataliepopescu:npopescu/read-as-enum-fix
Draft

nataliepopescu wants to merge 1 commit into
tock:mainfrom
nataliepopescu:npopescu/read-as-enum-fix

Conversation

@nataliepopescu

@nataliepopescu nataliepopescu commented Nov 17, 2026 •

Copy link
Copy Markdown

Pull Request Overview

This pull request fixes the field Value / RegisterLongName mismatch issue described in #100 by adding type parameter E to Field.

TODO or Help Wanted

This pull request still needs...

Checklist

  • Added unit and/or integration tests as appropriate.
  • Ran make test or make full.
  • All files that support comments have license headers

PR Contents

Documentation

  • Updated the relevant files in /doc.
  • No documentation updates are required.

AI Use

  • No AI was used in this PR.
  • AI was used in this PR. I have read Tock's AI policy and have properly disclosed my AI use below.

@ppannuto

Copy link
Copy Markdown
Member

Without thinking too deeply about this yet, I believe the reason that we didn't do this previously is because the actual E type is a pseduo-internal type, by which I mean it's created by the macro system and it's not obvious that it exists to users, except in the return type here (where it's not critical that a user can name the type).

On the core team call earlier today, we discussed this briefly, and I think the fuzzy consensus is that these enum types should somehow be more prominent and used more comprehensively (e.g., all registers, even those without fields (single-variant then), create enums and read returns an enum); but my instinct is to hold off on changing this API in isolation until we've had a chance to think through the enum story more comprehensively.

@bradjc

bradjc commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

I worked on a version of what we discussed, and, I'm not too excited about it.

The macro can create a .value() function on the enum, so reading the raw value becomes

register.read(Status::ERRORCOUNT).value()

The problem is, without something like this PR, Rust in this case can't tell what the enum type is, because it isn't used as the return value. So it actually has to look like:

register.read::<Status::ERRORCOUNT::Value>(Status::ERRORCOUNT).value()

which is clumsy.

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.

3 participants