chiark / gitweb /
Restructure ColouredString via a common trait.
authorSimon Tatham <anakin@pobox.com>
Tue, 9 Jan 2024 06:27:19 +0000 (06:27 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 10 Jan 2024 07:50:54 +0000 (07:50 +0000)
commit7cc91bf4f9d31805cbb629584dd04ad8d13f32ed
tree216e793dcbc363c86756145e7448e8a2c04a48a7
parent780723d7655eea34fd454db24534ba5850a2dd0f
Restructure ColouredString via a common trait.

Now ColouredString and ColouredStringSlice both implement the trait
ColouredStringCommon, and as many methods as possible are provided by
that trait, depending only on the unimplemented trait methods to get
the text and colours and &str.

This reduces the amount of code, and also makes points of use more
flexible, because I can implement the common trait not just for both
the actual types, but also references to them.

The only disappointment is that I wasn't able to also fold the four
identical impls of std::ops::Add into one via a single
doubly-quantified impl. But instead I got to deploy my first
macro_rules!, so that's something.

In the next commits I'll clean up now-unnecessary boilerplate at call
sites.
src/coloured_string.rs
src/editor.rs
src/file.rs
src/html.rs
src/text.rs
src/tui.rs