Skip to main content

cstr

Macro cstr 

Source
macro_rules! cstr {
    ($($arg:tt)*) => { ... };
}
Expand description

Parses and renders a farben markup string at compile time when possible.

With the compile feature, a bare literal like cstr!("[red]Error") is rendered at compile time and returns a [FarbenStr] — visible as such in cargo expand. Format arguments (explicit or implicit) fall through to runtime via color_runtime, with the markup validated at compile time first.

Without the compile feature, the markup is processed at runtime.

Returns a [FarbenStr] when rendered at compile time, or a String otherwise. Both types implement [Display], so println!("{}", cstr!(...)) works regardless of features.

This is the canonical replacement for the color() / color!() duality.

§Panics

Panics if the markup is invalid. Use try_color for error handling.

§Examples

use farben::prelude::*;
cprintln!("{}", cstr!("[green]Success!"));