taffy icon indicating copy to clipboard operation
taffy copied to clipboard

PrintTree and RoundTree: use Layout instead of &Layout

Open ThePuzzlemaker opened this issue 10 months ago • 1 comments

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 avatar Jun 18 '25 11:06 ThePuzzlemaker

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

ThePuzzlemaker avatar Jun 18 '25 11:06 ThePuzzlemaker