pub enum BorderStyle {
None,
Single,
Double,
Round,
Bold,
SingleDouble,
DoubleSingle,
Classic,
Arrow,
}Expand description
Available box drawing styles with semantic meaning and use cases.
Each style provides a different visual appearance optimized for specific use cases. This enum provides a convenient, type-safe way to select box styles without directly referencing character constants.
§Style Guidelines
- Single: Default choice for most applications, clean and readable
- Double: Use for emphasis, headers, or important content sections
- Round: Modern appearance, good for user-friendly interfaces
- Bold: Maximum emphasis, warnings, or critical information
- Mixed Styles: Unique visual effects, decorative purposes
- Classic: ASCII-only environments, legacy system compatibility
- Arrow: Special effects, directional indicators, creative designs
- None: Invisible spacing, layout without visible borders
§Performance Notes
All enum variants are zero-cost abstractions that compile to direct character constants. String parsing is optimized for performance with zero heap allocations.
§Examples
§Basic Usage
use cli_boxes::{BorderStyle, BoxChars};
// Convert enum to box characters
let box_chars = BoxChars::from(BorderStyle::Single);
assert_eq!(box_chars.top_left, '┌');
// Using the convenience method
let double_chars = BorderStyle::Double.chars();
assert_eq!(double_chars.top_left, '╔');§Dynamic Style Selection
use cli_boxes::BorderStyle;
fn get_style_for_severity(level: u8) -> BorderStyle {
match level {
0 => BorderStyle::None,
1 => BorderStyle::Single,
2 => BorderStyle::Bold,
3 => BorderStyle::Double,
_ => BorderStyle::Classic,
}
}
let style = get_style_for_severity(2);
let chars = style.chars();§Iteration and Discovery
use cli_boxes::BorderStyle;
// Display all available styles
for style in BorderStyle::all() {
let chars = style.chars();
println!("{:12} -> {}", style.to_string(), chars);
}§String Parsing with Error Handling
use cli_boxes::BorderStyle;
use std::str::FromStr;
// Parse from configuration files or user input
let styles = ["single", "double", "round", "invalid"];
for style_str in &styles {
match style_str.parse::<BorderStyle>() {
Ok(style) => println!("✓ Parsed '{}' as {:?}", style_str, style),
Err(e) => println!("✗ Error: {}", e),
}
}Variants§
None
No box characters (all spaces)
Single
Single-line box drawing characters: ┌─┐│┘─└│
Double
Double-line box drawing characters: ╔═╗║╝═╚║
Round
Rounded corner box drawing characters: ╭─╮│╯─╰│
Bold
Bold/thick line box drawing characters: ┏━┓┃┛━┗┃
SingleDouble
Single horizontal, double vertical: ╓─╖║╜─╙║
DoubleSingle
Double horizontal, single vertical: ╒═╕│╛═╘│
Classic
ASCII-compatible classic box characters: +─+|+─+|
Arrow
Arrow-based decorative box characters: ↘↓↙←↖↑↗→
Implementations§
Source§impl BorderStyle
impl BorderStyle
Trait Implementations§
Source§impl Clone for BorderStyle
impl Clone for BorderStyle
Source§fn clone(&self) -> BorderStyle
fn clone(&self) -> BorderStyle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BorderStyle
impl Debug for BorderStyle
Source§impl Display for BorderStyle
impl Display for BorderStyle
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the border style as a lowercase string.
§Examples
use cli_boxes::BorderStyle;
assert_eq!(BorderStyle::Single.to_string(), "single");
assert_eq!(BorderStyle::DoubleSingle.to_string(), "double_single");
assert_eq!(BorderStyle::Arrow.to_string(), "arrow");Source§impl From<BorderStyle> for BoxChars
impl From<BorderStyle> for BoxChars
Source§fn from(style: BorderStyle) -> Self
fn from(style: BorderStyle) -> Self
Converts a BorderStyle enum variant to its corresponding BoxChars.
§Examples
use cli_boxes::{BorderStyle, BoxChars};
let single_chars = BoxChars::from(BorderStyle::Single);
assert_eq!(single_chars, BoxChars::SINGLE);
let double_chars = BoxChars::from(BorderStyle::Double);
assert_eq!(double_chars, BoxChars::DOUBLE);Source§impl FromStr for BorderStyle
impl FromStr for BorderStyle
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses a string into a BorderStyle.
The parsing is case-insensitive and accepts both snake_case and kebab-case.
This implementation is optimized to avoid heap allocations.
§Examples
use std::str::FromStr;
use cli_boxes::BorderStyle;
assert_eq!("single".parse::<BorderStyle>().unwrap(), BorderStyle::Single);
assert_eq!("DOUBLE".parse::<BorderStyle>().unwrap(), BorderStyle::Double);
assert_eq!("single-double".parse::<BorderStyle>().unwrap(), BorderStyle::SingleDouble);
assert_eq!("double_single".parse::<BorderStyle>().unwrap(), BorderStyle::DoubleSingle);
// Error case
assert!("invalid".parse::<BorderStyle>().is_err());