Skip to content

refactor: validate Fdt on construction#23

Merged
m4tx merged 3 commits into
mainfrom
validate-fdt
Jan 8, 2026
Merged

refactor: validate Fdt on construction#23
m4tx merged 3 commits into
mainfrom
validate-fdt

Conversation

@m4tx

@m4tx m4tx commented Dec 23, 2025

Copy link
Copy Markdown
Collaborator

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.
Comment thread src/standard/ranges.rs Outdated
Comment thread src/standard/ranges.rs Outdated
Comment thread src/standard/reg.rs Outdated
Comment thread src/error.rs Outdated
Comment thread src/standard/mod.rs
@@ -0,0 +1,238 @@
// Copyright 2025 Google LLC

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, for some reason I was sure this recommendation was removed some time ago. I don't really like this policy as it results in top-level modules containing way too many files (and sensible editors will differentiate between a/mod.rs and b/mod.rs even in the tabs anyway), but if it's still the current recommendation, I won't fight with that. We'll need to update the rest of the files then.

@m4tx m4tx requested a review from qwandor January 8, 2026 14:19
@m4tx m4tx merged commit 667d309 into main Jan 8, 2026
26 checks passed
@m4tx m4tx deleted the validate-fdt branch January 8, 2026 14:22
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