Don't return TaffyResult when Taffy methods can't fail.#520
Open
gibbz00 wants to merge 8 commits into
Open
Conversation
Collaborator
I really like this, but I'd prefer to do this in a separate PR to keep this reviewable. |
8cae1ba to
58daf29
Compare
Initial commit for: DioxusLabs#519. Affected methods: `new_leaf`, `compute_layout`, `new_leaf_with_measure`, `new_with_children`, `remove`, `set_measure`, `add_child`, `set_children`, `child_count`, `children`, `layout`, `set_style`, `style`, `mark_dirty`, `dirty`. Should be noted that many of the methods can still panic due to the frequent use of direct array indexing.
Accompanies: 4a9ac5e
Accompanies: 4a9ac5e
Member
|
I don’t think removing Clone from NodeId is going to work. We use that internally to store NodeId’s during layout (currently we also rely on NodeId being Copy, but that isn’t strictly necessary). And one would always be able to obtain duplicate NodeId’s by for example calling .parent() twice. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #519.
Affected methods:
new_leaf,compute_layout,new_leaf_with_measure,new_with_children,remove,set_measure,add_child,set_children,child_count,children,layout,set_style,style,mark_dirty,dirty.TODO:
Reduce implicit panicking possibilities.(See: #520 (comment))cargo gentestRELEASES.mdFeedback wanted
As commented by @nicoburns: Many of the methods can still panic due to the frequent use of direct array indexing. But this shouldn't really be an issue since the keys themselves can't be created without them being registered by the
Taffyinstance, and removal takes ownership of theNodeIds. But this can unfortunately easily be bypassed by cloning them, or by creating them it from anotherTaffyinstance.So rather than creating checked/unchecked method equivalents, I would suggest removing these runtime panic possibilities by continuing to leverage Rust's build in memory safety and module scoping rules. This means passing borrowed
NodeIds to methods that don't mutate any values, and removing theNodeId'sCloneimplementation etc.