这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@ThePuzzlemaker
Copy link
Contributor

@ThePuzzlemaker ThePuzzlemaker commented Jun 18, 2025

Objective

This PR allows the use of PrintTree and RoundTree for smart pointer interfaced trees.

Let me know how is best to update the changelog if you need me to.

Context

In my use of taffy, I need my tree implementation to be within a RefCell<T>. This is already possible with most tree traits, as they have generic associated types implementing traits such as CoreStyle, so I can make a newtype over Ref<'a, Style> with Ref::map and make it work. However, RoundTree and PrintTree do not allow this, as they return a plain &Layout reference instead of an associated type.

I looked in the code, and in the tree rounding code, the &Layout is already copied. Additionally, printing the tree is likely more of a debugging or testing feature, so I feel that copying is warranted here instead of having to introduce some sort of new trait like CoreStyle for Layout which would potentially break more code internally.

@ThePuzzlemaker
Copy link
Contributor Author

Woops, forgot to update the examples. Will do that.

Copy link
Collaborator

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

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

I definitely want to enable the RefCell use case. And the logic around rounding and printing makes sense to me. However, for TaffyTree I believe these methods are currently the only way to access the computed layout and I think we'd still want a way to access by reference there (as 84 bytes is kinda bigish to be copying around).

So could we either:

  • Add inherent methods to TaffyTree to get layout by ref
  • Or add associated types so that we can return impl Deref<Target = Layout>

?

@nicoburns nicoburns merged commit 6408bd7 into DioxusLabs:main Aug 2, 2025
26 checks passed
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