Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating colorized things in const context #62

Open
blt-r opened this issue Jun 6, 2022 · 1 comment
Open

Allow creating colorized things in const context #62

blt-r opened this issue Jun 6, 2022 · 1 comment

Comments

@blt-r
Copy link

blt-r commented Jun 6, 2022

We still cant put conts fn in impl Trait, so we can't mark methods of OwoColorize as const. But const_fn_trait_bound is already stable. Which means that we can allow creating FgColorDisplay (and others) in const context.

For example, like this:

impl<'a, C: Color, T> FgColorDisplay<'a, C, T> {
    pub const fn new(thing: &'a T) -> Self {
        Self(thing, PhantomData)
    }
}
#[test]
fn const_fg_color_display() {
    const YELLOW_FISH: FgColorDisplay<'static, Yellow, &'static str> = FgColorDisplay::new(&"><>");

    assert_eq!("\u{1b}[33m><>\u{1b}[39m", YELLOW_FISH.to_string())
}

I personally think having colorized constants is pretty useful (I created this issue because I wanted to do that, but found out, that I can't). So maybe we can add support for that in some form or another?

@jam1garner
Copy link
Owner

I will try to look into that as I definitely understand the desire. At minimum as trait const fns continue along more it'll definitely be better supported

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

No branches or pull requests

2 participants