chiark / gitweb /
Changed my mind about using Box<dyn TextFragment>.
authorSimon Tatham <anakin@pobox.com>
Thu, 28 Dec 2023 11:06:15 +0000 (11:06 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 28 Dec 2023 11:06:15 +0000 (11:06 +0000)
commit0d428ad0f44c91d11c986c15084c6a352fc7335e
treed75d098321af313747005dd31a13bc81ac4e6ff7
parent18f91f2c9ea47b10c014443b4234ca96382032a5
Changed my mind about using Box<dyn TextFragment>.

I think it's going to be a better idea to have each user of
TextFragment separately make an enum that permits precisely the kinds
of TextFragment they want. Firstly, this means we can be statically
sure no rogue weird ones got in there by accident; secondly, it
immediately solves all the problems of finding the ones that need
special handling at render time (extensible-file indicators etc).

And thirdly - this is definitely a thing I'm having trouble getting
used to in Rust - if I _do_ need one particular client of TextFragment
to do everything by means of a list of perfectly generic Box<dyn
TextFragment>, I can choose to do it in _that_ client module, and
text.rs doesn't have to lift a finger to support it!
src/menu.rs
src/text.rs