-
Notifications
You must be signed in to change notification settings - Fork 9
Remove most Datetime panic paths #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove most Datetime panic paths #10
Conversation
760f153 to
98c4a6c
Compare
98c4a6c to
ae19b5f
Compare
There was a problem hiding this 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 refactors the Datetime type to eliminate most panic paths by introducing a type-safe Month enum and removing array indexing operations. The changes improve code safety for embedded systems where panics can be catastrophic, while maintaining strict validation through comprehensive testing that exercises every date from 1970 to 2500.
Key changes:
- Introduced
Monthenum with type-safe month representation (1-12) usingnum_enumfor conversions - Replaced panic-prone array indexing with const methods on the
Monthenum - Added clippy lints to warn against panic-inducing operations (expect_used, unwrap_used, panic, etc.)
Reviewed changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| supply-chain/imports.lock | Added rustversion audit entries for dependency chain verification |
| supply-chain/audits.toml | Added audits for num_enum, num_enum_derive, and rustversion dependencies |
| embedded-mcu-hal/Cargo.toml | Added num_enum dependency and clippy lints to prevent panics |
| Cargo.lock | Updated with num_enum and rustversion dependency entries |
| embedded-mcu-hal/src/time/mod.rs | Exported the new Month enum publicly |
| embedded-mcu-hal/src/time/datetime.rs | Replaced u8 month with Month enum, removed array-based month logic, updated all tests to use Month enum, added comprehensive date roundtrip test |
| embedded-mcu-hal/src/lib.rs | Whitespace formatting changes only |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
4ce21df to
87c7289
Compare
…o stable is_multiple_of to satisfy both nightly clippy and stable clippy simultaneously
felipebalbi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just line endings on one file again.
This change removes most panic paths from the Datetime type. Doing this required a breaking interface change to how months are expressed. Additionally, it adds some tests that exercise every date for the next couple hundred years to catch any date-specific bugs.
There are still a couple expects() in the chrono conversion path because we know about some invariants that the compiler can't really know about, but those are all behind a feature flag. I don't see a path to removing these without either using some sort of unsafe code or making an operation that is infallible have a fallible API. Compatibility with the chrono lib is behind a feature flag, though, so panic-sensitive clients can opt to not enable the chrono feature.