Skip to content

Comments

Ai improvements#164

Merged
rneswold merged 6 commits intoDrMemCS:mainfrom
rneswold:ai-improvements
Jan 23, 2026
Merged

Ai improvements#164
rneswold merged 6 commits intoDrMemCS:mainfrom
rneswold:ai-improvements

Conversation

@rneswold
Copy link
Contributor

These API improvements were the recommendation of ChatGPT in GitHub's Copilot feature. Some of the code it flagged was stuff I wrote earlier when I was less experienced with Rust. They were very good changes. Although ChatGPT showed examples of how the improvements would look and be used, I wrote all the changes required in the drmem-api and driver crates.

The first change converted a boxed closure into an enumerated type which required no allocating.

The second was to use async methods in the driver crate instead of specifying complicated, boxed, pinned futures with specialty traits.

Next, functions and methods that needed any path of a device name were requiring the caller to create the correct type. Now we've defined an Into<> trait so callers can pass &str and the functions will convert it internally. This really cleaned up some code.

Finally, instead of hand-writing code to verify and access the driver config parameters, we now use serde. A driver can describe their parameters in a struct and serde will do the validation. This is a huge usability win for authors of device drivers.

This was recommended by an AI. As an inexperienced Rust programmer, I
had drivers reply to settings through a boxed closure. What was I
thinking?

The AI (ChatGPT 5 in GitHub's Copilot) recommended using a type
instead. This allows me to define methods that are simpler to use,
avoids an extra heap allocation for every incoming setting, and
define the methods to consume the type so you can only reply once.
The AI also recommended using `async` methods instead of forcing a
boxed, pinned future -- like I specified. This should reduce heap
allocations.

Ideally the `Driver` trait should be using the async notation but I
couldn't figure out a way to add the `Send` requirement to the Future
that's returned.
Define `TryFrom` traits for strings and string slices. Update some
methods so they accept types that can be converted. This simplifies
the API for driver writers in that they don't have to do the
conversions.

This commit was recommended by an AI, although I did the
modifications.
I was including `serde_derive`, but that automatically gets included
when you enable the "derive" feature on `serde`.
Rather than have handwritten methods to validate and obtain parameters
from the driver config map, the AI recommended using the `serde`
crate.

This large commit redefines `DriverConfig` to be a wrapping structure
that adds useful conversions into a driver's specific needs.
@rneswold rneswold merged commit ccc2b72 into DrMemCS:main Jan 23, 2026
3 checks passed
@rneswold rneswold deleted the ai-improvements branch January 23, 2026 21:49
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