refactor: validate Fdt on construction#23
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.
| @@ -0,0 +1,238 @@ | |||
| // Copyright 2025 Google LLC | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.