Skip to content

Better reflect::Struct field unpacking#662

Merged
mkeeter merged 3 commits into
masterfrom
mkeeter/struct-field-unpacking
May 21, 2026
Merged

Better reflect::Struct field unpacking#662
mkeeter merged 3 commits into
masterfrom
mkeeter/struct-field-unpacking

Conversation

@mkeeter
Copy link
Copy Markdown
Contributor

@mkeeter mkeeter commented May 12, 2026

(staged on #658)

Adds a Struct::field function which unpacks a strongly-typed field, then uses it in relevant places.

@mkeeter mkeeter requested a review from labbott May 12, 2026 21:49
@mkeeter mkeeter mentioned this pull request May 12, 2026
@mkeeter mkeeter force-pushed the mkeeter/remove-options branch from df309fa to 6a02ee1 Compare May 13, 2026 21:41
@mkeeter mkeeter force-pushed the mkeeter/struct-field-unpacking branch from c7878a4 to 4bad0ff Compare May 13, 2026 21:41
@mkeeter mkeeter force-pushed the mkeeter/remove-options branch from 6a02ee1 to b9e0537 Compare May 14, 2026 16:20
@mkeeter mkeeter force-pushed the mkeeter/struct-field-unpacking branch from 4bad0ff to 1469947 Compare May 14, 2026 16:20
@mkeeter mkeeter force-pushed the mkeeter/remove-options branch from b9e0537 to c1f68b4 Compare May 14, 2026 16:48
@mkeeter mkeeter force-pushed the mkeeter/struct-field-unpacking branch 2 times, most recently from 5c809af to 856c262 Compare May 14, 2026 19:08
@mkeeter mkeeter force-pushed the mkeeter/remove-options branch from c1f68b4 to 57d5f1c Compare May 14, 2026 19:08
Copy link
Copy Markdown
Contributor

@labbott labbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mkeeter mkeeter force-pushed the mkeeter/remove-options branch from 57d5f1c to 9950776 Compare May 18, 2026 19:30
@mkeeter mkeeter force-pushed the mkeeter/struct-field-unpacking branch 2 times, most recently from 7f67b46 to bb9d369 Compare May 18, 2026 19:53
@mkeeter
Copy link
Copy Markdown
Contributor Author

mkeeter commented May 18, 2026

Tested on niles to make sure I didn't mess anything up with the command changes

matt@niles ~ () $ env RUST_BACKTRACE=1 pfexec ./humility -t gimlet-d spd
humility: attached to 0483:3754:000D00344741500820383733 via ST-Link V3
ADDR MANUFACTURER              PART                 WEEK YEAR
   0 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   1 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   2 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   3 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   4 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   5 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   6 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   7 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   8 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
   9 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
  10 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
  11 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
  12 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
  13 Micron Technology         36ASF8G72PZ-3G2E1      34 2022
  14 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
  15 Micron Technology         36ASF8G72PZ-3G2F1       2 2023
matt@niles ~ () $ env RUST_BACKTRACE=1 pfexec ./humility -t gimlet-d net counters
humility: attached to 0483:3754:000D00344741500820383733 via ST-Link V3
 -------------------------------------------------------------------
 |  KSZ8463  |         Transmit         |         Receive          |
 |           |   UC   |   BC   |   MC   |   UC   |   BC   |   MC   |
 |-----------|--------|--------|--------|--------|--------|--------|
 | Port 1    |      0 |      0 |     33 |      0 |      0 |      0 |
 | Port 2    |      0 |      0 |     33 |      0 |      0 |      0 |
 | Port 3    |      0 |      0 |      0 |      0 |      0 |     66 |
 -------------------------------------------------------------------

 -------------------------------------------------------
 |     VSC8562     |     Transmit    |     Receive     |
 |                 |  Good  |   Bad  |  Good  |   Bad  |
 |-----------------------------------------------------|
 | Port 0 | MAC    |     33 |      0 |      0 |      0 |
 |        | Media  |      0 |      0 |     33 |      0 |
 | Port 1 | MAC    |     33 |      0 |      0 |      0 |
 |        | Media  |      0 |      0 |     33 |      0 |
 -------------------------------------------------------

            ┌──────────────────┐            ┌───────────────────┐
            │ KSZ8463          │            │ VSC85x2           │
            │                  │tx        rx│                   │tx
            │                33├───────────►│33               33├───────►
            │                  │1          0│                   │0
┌────┐    rx│                 0│◄───────────┤0                 0│◄───────
│    ├─────►│66                │rx        tx│                   │rx
│ SP │     3│                  │            │                   │
│    │◄─────┤0                 │tx        rx│                   │tx
└────┘    tx│                33├───────────►│33               33├───────►
            │                  │2          1│                   │1
            │                 0│◄───────────┤0                 0│◄───────
            │                  │rx        tx│                   │rx
            └──────────────────┘            └───────────────────┘
                                             MEDIA           MAC

matt@niles ~ () $ env RUST_BACKTRACE=1 pfexec ./humility -t gimlet-d net status
humility: attached to 0483:3754:000D00344741500820383733 via ST-Link V3
          ------------------              ---------------------
          |            UP  1 <----------> 0  UP          DOWN 0 <------>
  SP <--> 3  KSZ8463       |              |      VSC85x2      |
     RMII |            UP  2 <----------> 1  UP          DOWN 1 <------>
          ------------------  100BASE-FX  ---------------------  SGMII

(in fact, I had messed up one of the counter array sizes)

@mkeeter mkeeter force-pushed the mkeeter/struct-field-unpacking branch from bb9d369 to 327fc04 Compare May 20, 2026 19:40
@mkeeter mkeeter force-pushed the mkeeter/remove-options branch from 9950776 to 3021c11 Compare May 20, 2026 19:40
@mkeeter mkeeter requested a review from Copilot May 20, 2026 20:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves reflected struct/tuple field access by adding Struct::field / Tuple::field helpers that deserialize strongly-typed members via Load, and then updates downstream call sites to use the new API.

Changes:

  • Add Struct::field / Tuple::field typed accessors in humility-core::reflect, plus new Load impls (e.g., for Struct, Tuple, Base, ()).
  • Refactor SPD parsing to use typed field extraction for nested SPD buffers.
  • Refactor net command decoding (MAC address, link status, counters) to use typed field extraction.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
humility-spd/src/lib.rs Simplifies nested SPD buffer unpacking using Struct::field.
humility-core/src/reflect.rs Introduces typed field helpers and additional Load impls; tweaks a field lookup error string.
cmd/net/src/lib.rs Replaces manual reflected decoding with Struct::field / Tuple::field in several command paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread humility-core/src/reflect.rs Outdated
Comment thread humility-core/src/reflect.rs
Comment thread cmd/net/src/lib.rs
@mkeeter mkeeter force-pushed the mkeeter/struct-field-unpacking branch from 327fc04 to e0f22cf Compare May 20, 2026 20:09
@mkeeter mkeeter force-pushed the mkeeter/remove-options branch from 3021c11 to d2b73a4 Compare May 20, 2026 20:09
Base automatically changed from mkeeter/remove-options to master May 20, 2026 20:44
@mkeeter mkeeter force-pushed the mkeeter/struct-field-unpacking branch from e0f22cf to 2740bf7 Compare May 20, 2026 20:45
@mkeeter mkeeter merged commit e9af434 into master May 21, 2026
12 checks passed
@mkeeter mkeeter deleted the mkeeter/struct-field-unpacking branch May 21, 2026 13:43
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