#[non_exhaustive]pub enum Color {
Named(String),
Hex(String),
Rgb(u8, u8, u8),
}Expand description
Color specification for borders and backgrounds
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Named(String)
Named color (e.g., “red”, “blue”, “green”)
Hex(String)
Hexadecimal color code (e.g., “#FF0000”, “#00FF00”)
Rgb(u8, u8, u8)
RGB color values (red, green, blue components 0-255)
Implementations§
Source§impl Color
impl Color
Sourcepub fn validated(value: &str) -> Result<Self, BoxenError>
pub fn validated(value: &str) -> Result<Self, BoxenError>
Try to create a color from a string, validating named colors and hex format.
This method validates the color specification and returns an error if the color name is not recognized or the hex format is invalid.
§Supported Named Colors
Standard colors: black, red, green, yellow, blue, magenta, cyan, white
Bright colors: bright_black, bright_red, bright_green, bright_yellow,
bright_blue, bright_magenta, bright_cyan, bright_white
§Hex Format
Hex colors must start with # and be exactly 6 characters (e.g., #FF0000).
§Examples
use boxen::Color;
// Valid named color
let red = Color::validated("red").unwrap();
// Valid hex color
let orange = Color::validated("#FF8000").unwrap();
// Invalid color name
assert!(Color::validated("invalid_color").is_err());
// Invalid hex format
assert!(Color::validated("#GGG").is_err());§Errors
Returns BoxenError::InvalidColor if:
- The color name is not recognized
- The hex format is invalid (wrong length or invalid characters)
- The string contains whitespace or special characters
Trait Implementations§
Source§impl From<&str> for Color
impl From<&str> for Color
Source§fn from(value: &str) -> Self
fn from(value: &str) -> Self
Creates a color from a string without validation.
This implementation accepts any string and does not validate whether
the color name is valid or the hex format is correct. For validated
color creation, use Color::validated(s) instead.
§Examples
use boxen::Color;
// Accepts any string without validation
let color: Color = "red".into();
let invalid: Color = "not_a_color".into(); // No error, but may fail at render time