Skip to content

Conversation

@m4tx
Copy link
Collaborator

@m4tx m4tx commented Dec 23, 2025

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.

@m4tx m4tx requested a review from qwandor December 23, 2025 18:17
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
Copy link
Collaborator

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
Copy link
Collaborator

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`.
Copy link
Collaborator

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 {
Copy link
Collaborator

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
Copy link
Collaborator

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.

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.

2 participants