rust-cli / anstyle

ANSI text styling
https://docs.rs/anstyle
Other
106 stars 16 forks source link

Make `anstyle::Style::render` const #160

Closed stevenengler closed 7 months ago

stevenengler commented 8 months ago

This is a very low priority feature request. I think it would be nice if anstyle::Style::render were const since most other Style methods are const, and it makes it a little nicer if you want to put the style in a module-level constant and not need to call render() everywhere that it's used.

Example:

const ERROR_STYLE: StyleDisplay = Style::new().bold().render();

The problem is that render() returns impl Display + Copy + Clone which is not nameable and cannot be placed in a constant, so StyleDisplay would need to be made public and the signature of render() would need to be changed.

If you're open to this change, let me know and I can make a PR.

epage commented 8 months ago

Wish we had impl types on const.

I can see the value to this. I'm trying to keep the API small to keep the compatibility guarantees low and to keep the focus on the primary purpose, being used in public APIs. Being used for styling is a secondary benefit which I use but I also try to avoid optimizing for.

Will need to think about this more.

stevenengler commented 8 months ago

Okay, probably not worth changing now, but maybe worth considering if in the future you need to make API changes for some other reason.

epage commented 7 months ago

After discussions in #166, I'm moving forward with #165 which I believe negates the need for this issue. I'm going ahead and closing it. Let us know if there is a reason to keep it open!