Skip to content

feat: Add from_hex_str methods to Color and RgbColor#332

Open
joshtriplett wants to merge 3 commits into
rust-cli:mainfrom
joshtriplett:anstyle-from-hex-str
Open

feat: Add from_hex_str methods to Color and RgbColor#332
joshtriplett wants to merge 3 commits into
rust-cli:mainfrom
joshtriplett:anstyle-from-hex-str

Conversation

@joshtriplett

Copy link
Copy Markdown
Contributor

Converting from a 3-digit or 6-digit hex color is a common operation in various formats, including HTML/CSS, SVG, and Git. Add it to anstyle.

I've based this PR on #331, which fixes a bug in this logic.

A color like `#abc` should be interpreted as equivalent to `#aabbcc`.
Converting from a 3-digit or 6-digit hex color is a common operation in
various formats, including HTML/CSS, SVG, and Git. Add it to anstyle.
@epage

epage commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

This is pushing further at the boundaries of anstyles original intent which has me hesitant.

The limited scope was for two reasons

  • minimize risk of breaking changes so people can trust to put this in their APIs
  • minimize compile times so people don't question adding yet another dependency

The main impact I can see this having is more in the "well, you parse X, but what about Y".

Beyond, the question is where do we draw the line?

@joshtriplett

Copy link
Copy Markdown
Contributor Author

@epage I originally considered making this pub from anstyle-git, but that felt like the wrong place, since a CSS color parser shouldn't be pulling in anstyle-git just to get a helper function. A one-function anstyle-hex crate seemed gratuitous, though I'll do that if you'd prefer.

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.

2 participants