-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: validate Fdt on construction
#23
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
base: main
Are you sure you want to change the base?
Conversation
This makes the APIs more ergonomic, as most of the methods that used to return `Result<T, E>`, return `T` now instead, making it much easier to work with, especially in case of iterators. This obviously causes the constructor to run in linear time, which shouldn't be a huge problem considering that any sensible use of the parser will require linear-time traversal time anyway. In case this would be a problem, however, a separate constructor that skips the validation (and causes the traverse methods to panic instead) is added. This also allows us to unify some error handling between in-memory and internal representation APIs, bringing us closer to unifying these two APIs under a common trait, and supporting the "standard nodes & properties" for the internal representation variant.
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns `FdtError::TooManyCells` if the child-bus-address doesn't fit in |
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.
This comment needs updating, it is now StandardError rather than FdtError.
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns `FdtError::TooManyCells` if the parent-bus-address doesn't fit |
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.
StandardError rather than FdtError.
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns `FdtError::TooManyCells` if the address doesn't fit in `T`. |
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.
Update this comment.
| #[error( | ||
| "prop-encoded-array property was {size} bytes, but should have been a multiple of {chunk} cells" | ||
| )] | ||
| PropEncodedArraySizeMismatch { |
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.
This should be a PropertyError.
| @@ -0,0 +1,238 @@ | |||
| // Copyright 2025 Google LLC | |||
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.
https://doc.rust-lang.org/reference/items/modules.html#r-items.mod.outlined.search-mod recommends naming module files like src/standard.rs rather than src/standard/mod.rs, since Rust 1.30. It makes it easier to find the right file when searching by filename in an editor or codesearch.
This makes the APIs more ergonomic, as most of the methods that used to return
Result<T, E>, returnTnow instead, making it much easier to work with, especially in case of iterators.This obviously causes the constructor to run in linear time, which shouldn't be a huge problem considering that any sensible use of the parser will require linear-time traversal time anyway. In case this would be a problem, however, a separate constructor that skips the validation (and causes the traverse methods to panic instead) is added.
This also allows us to unify some error handling between in-memory and internal representation APIs, bringing us closer to unifying these two APIs under a common trait, and supporting the "standard nodes & properties" for the internal representation variant.