ratatui icon indicating copy to clipboard operation
ratatui copied to clipboard

Symbol Sets require &'static instead of using lifetime generics

Open mierak opened this issue 9 months ago • 3 comments

Problem

Currently it is impossible to create a symbol set for borders with runtime values (unless I Box::leak() the symbols to create static refs). That is because https://docs.rs/ratatui/latest/ratatui/symbols/border/struct.Set.html requires &'static str.

Solution

Make Set take a lifetime generic/Cow which is used for the symbols.

I assume this would be a breaking change in case someone is storing the Sets, though it should be a fairly small change for ratatui itself. So I am unsure whether this is even doable at this point but would be nice to have.

Or is there any alternative that I am missing? I am trying to provide a way to specify border symbol set via config file in my program.

mierak avatar Mar 17 '25 00:03 mierak

Yeah, most of this comes from pre-ratatui days. I don't mind changing this, but would suggest that if we're going to do it, that we make the change across all the Sets in the symbols, not just one. We should also try to understand how it breaks for users.

I suspect that although breaking, it may be the sort of break which only rarely causes problems to actual code - perhaps experiment with some ideas about this to understand what the actual breakage is, and do some github searches to see how prevalent custom usages are to understand the real world impact. (search protip - "AND (NOT org:ratatui) AND (NOT is:fork)" filters out irrelevant code)

joshka avatar Mar 17 '25 00:03 joshka

I suspect that although breaking, it may be the sort of break which only rarely causes problems to actual code

I suspect so too. There is not much reason to use them in the code other than to directly pass to ratatui.

this dirty search shows 186 results. Some are false positives, some are surely missed, some projects show multiple times (funnily enough, one of the projects is mine). So I think it is safe to assume that the impact is in low hundreds at most.

My approach was to find files containing ratatui to account for use and then any type usages containing the Set keyword prepended by either space or : to account for both import of Set and using a fully qualified path.

mierak avatar Mar 17 '25 01:03 mierak

I'd be okay to change this as suggested, the breakage seems relatively low-risk.

orhun avatar Mar 19 '25 21:03 orhun

It would be good to perhaps aim to get this into 0.30, mainly because it's a large change where many things move to ratatui-core, and would be better to break once rather than at some later date.

joshka avatar May 29 '25 18:05 joshka