BorderStyle

Enum BorderStyle 

Source
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

Source

pub fn chars(self) -> BoxChars

Returns the BoxChars associated with this border style.

This is a convenience method that’s equivalent to BoxChars::from(style).

§Examples
use cli_boxes::BorderStyle;

let style = BorderStyle::Bold;
let chars = style.chars();
assert_eq!(chars.top, '━');
Source

pub fn all() -> impl Iterator<Item = Self>

Returns an iterator over all available border styles.

This is a convenience method that uses the EnumIter trait.

§Examples
use cli_boxes::BorderStyle;

for style in BorderStyle::all() {
    println!("Style: {:?}", style);
}

Trait Implementations§

Source§

impl Clone for BorderStyle

Source§

fn clone(&self) -> BorderStyle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BorderStyle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for BorderStyle

Source§

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

Source§

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

Source§

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());
Source§

type Err = ParseBorderStyleError

The associated error which can be returned from parsing.
Source§

impl Hash for BorderStyle

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoEnumIterator for BorderStyle

Source§

impl PartialEq for BorderStyle

Source§

fn eq(&self, other: &BorderStyle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BorderStyle

Source§

impl Eq for BorderStyle

Source§

impl StructuralPartialEq for BorderStyle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.