Skip to content

Conversation

@BioTomateDE
Copy link
Contributor

@BioTomateDE BioTomateDE commented Dec 15, 2025

I mostly changed the clunky where-clauses in the Colorize trait.

Before:

fn blue(self) -> ColoredString
where
    Self: Sized,
{
    self.color(Color::Blue)
}

After:

fn blue(self) -> ColoredString
    self.color(Color::Blue)
}

For this to work, I added the Sized constraint in the trait itself:

pub trait Colorize: Sized

This has no caveats: The self parameter is passed in all methods, so the "globalization" of the constraint has no downsides.

The rest of the changes were carefully applied lints: I added const to some internal functions, but made sure to keep public functions non-const to not potentially force breaking API changes later. Also, has_wrote is not proper English lol.

If there is room for improvement or I made some mistake, please let me know.

@Schlafhase
Copy link

Mods, please merge this immediately. I am really looking forward to this great feature. Can't wait!!!

@spenserblack spenserblack requested a review from Copilot December 15, 2025 23:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Colorize trait to improve code cleanliness by removing repetitive where Self: Sized constraints and applying various code quality improvements. The changes include adding Sized as a trait bound on Colorize itself, making internal functions const, improving variable naming, and fixing formatting issues.

  • Added Sized constraint to the Colorize trait definition, eliminating the need for per-method where clauses
  • Made internal helper functions const while keeping public API non-const
  • Renamed has_wrote to has_written for correct grammar and improved various code formatting issues

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/lib.rs Refactored Colorize trait with Sized bound, removed per-method where clauses, renamed has_wrote to has_written, simplified generic constraints, and added spacing between struct fields
src/style.rs Made to_str() and to_u8() functions const, removed unnecessary parentheses in filter closure, and added whitespace for readability
src/color.rs Made into_truecolor() function const and added blank line for formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

src/lib.rs Outdated
self.on_color(Color::AnsiColor(color.into()))
}
fn on_color<S: Into<Color>>(self, color: S) -> ColoredString;
fn on_color<T: Into<Color>>(self, color: T) -> ColoredString;
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic parameter was renamed from S to T, creating inconsistency with the color method on line 216 which still uses S. Both methods should use the same generic parameter name for consistency.

Suggested change
fn on_color<T: Into<Color>>(self, color: T) -> ColoredString;
fn on_color<S: Into<Color>>(self, color: S) -> ColoredString;

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@spenserblack spenserblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good to me! Thanks! Just this small nitpick. What do you think?

@spenserblack spenserblack merged commit 192598d into colored-rs:master Dec 16, 2025
13 of 14 checks passed
@spenserblack
Copy link
Collaborator

https://github.com/colored-rs/colored/actions/runs/20279679954/job/58238026056 says that this requires a new version, but, given that it's impossible to implement the trait on an unsized type AFAIK this is not in fact breaking IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants