-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
PlanMeta issueMeta issuecode qualityIssue is related to refactoring or improving code quality overall.Issue is related to refactoring or improving code quality overall.feature requestNew feature or requestNew feature or request
Milestone
Description
Motivation:
The current device instantiation API (e.g. Button::new_inverted_pullup, etc.) pis ergonomic but not scalable as the number of options grows. It’s also tightly coupled to runtime code and doesn’t support config-based instantiation (TOML/YAML/JSON), which limits flexibility for many real-world use cases.
We propose to replace the current serde support (tied to live device instances) with Builder-based configuration objects for all hardware devices. Builders can optionally be made serializable via a feature-flagged "serde".
Expectation:
- All current serde-related serialization/deserialization is removed from runtime types.
- All devices (and appropriate hardware structures) expose a Builder struct for construction.
- An optional feature "serde" allows serialization/deserialization of these builders.
- Builders may be renamed to Config when exposed via serde to make their intent clearer.
Proposal
Introduce per-device Builder types (possibly named Config when exposed via serde), e.g. ButtonBuilder. These will:
- Be used to construct devices fluently in Rust code.
- Be optionally serializable/deserializable via serde (with a feature flag).
- Completely replace the existing serde implementation, which currently exposes live device types to serialization.
Example
let button = ButtonBuilder::new()
.pin(2)
.pullup()
.inverted()
.debounce(20)
.build(&board)?;Or from config file (enabled with serde):
[[buttons]]
pin = 2
pull = "up"
inverted = true
debounce = 20Parsed all devices and built:
#[cfg(feature = "serde")]
let config: DeviceConfig= toml::from_str(...)?;
config.buttons.into_iter().try_for_each(|b| b.build(&board))?;Metadata
Metadata
Assignees
Labels
PlanMeta issueMeta issuecode qualityIssue is related to refactoring or improving code quality overall.Issue is related to refactoring or improving code quality overall.feature requestNew feature or requestNew feature or request