BoxChars

Struct BoxChars 

Source
pub struct BoxChars {
    pub top_left: char,
    pub top: char,
    pub top_right: char,
    pub right: char,
    pub bottom_right: char,
    pub bottom: char,
    pub bottom_left: char,
    pub left: char,
}
Expand description

A collection of Unicode characters used for drawing boxes in CLI applications.

This struct contains all the necessary characters to draw a complete box: corners, horizontal lines, and vertical lines. Each field represents a specific position in the box structure.

§Box Structure

top_left ──── top ──── top_right
   │                      │
  left                  right
   │                      │
bottom_left ── bottom ── bottom_right

§Memory Layout

BoxChars is a compact struct containing 8 char values (32 bytes total on most platforms). All predefined constants are evaluated at compile time for zero runtime cost.

§Thread Safety

BoxChars implements Send and Sync, making it safe to use across threads. All operations are immutable after construction.

§Examples

§Using Predefined Styles

use cli_boxes::BoxChars;

// Use predefined single-line box characters
let single = BoxChars::SINGLE;
assert_eq!(single.top_left, '┌');
assert_eq!(single.top, '─');
assert_eq!(single.top_right, '┐');

// Double-line for emphasis
let double = BoxChars::DOUBLE;
assert_eq!(double.top_left, '╔');

§Custom Box Creation

use cli_boxes::BoxChars;

// Direct constructor
let custom = BoxChars::new('*', '-', '*', '|', '*', '-', '*', '|');

// Builder pattern (recommended for readability)
let builder_box = BoxChars::builder()
    .corners('*')
    .horizontal('-')
    .vertical('|')
    .build();

assert_eq!(custom, builder_box);

§Drawing a Complete Box

use cli_boxes::BoxChars;

fn draw_box(chars: &BoxChars, width: usize, height: usize) -> String {
    let mut result = String::new();
     
    // Top border
    result.push(chars.top_left);
    result.push_str(&chars.top.to_string().repeat(width.saturating_sub(2)));
    result.push(chars.top_right);
    result.push('\n');
     
    // Side borders
    for _ in 0..height.saturating_sub(2) {
        result.push(chars.left);
        result.push_str(&" ".repeat(width.saturating_sub(2)));
        result.push(chars.right);
        result.push('\n');
    }
     
    // Bottom border
    result.push(chars.bottom_left);
    result.push_str(&chars.bottom.to_string().repeat(width.saturating_sub(2)));
    result.push(chars.bottom_right);
     
    result
}

let box_str = draw_box(&BoxChars::SINGLE, 5, 3);
println!("{}", box_str);
// Output:
// ┌───┐
// │   │
// └───┘

Fields§

§top_left: char

Top-left corner character

§top: char

Top border character (repeated horizontally)

§top_right: char

Top-right corner character

§right: char

Right border character (repeated vertically)

§bottom_right: char

Bottom-right corner character

§bottom: char

Bottom border character (repeated horizontally)

§bottom_left: char

Bottom-left corner character

§left: char

Left border character (repeated vertically)

Implementations§

Source§

impl BoxChars

Source

pub const NONE: Self

Creates a box with no visible characters (all spaces).

This is useful when you want to maintain box structure without visible borders, or as a fallback when no box styling is desired.

Source

pub const SINGLE: Self

Creates a box using single-line Unicode box-drawing characters.

This is the most commonly used box style, providing clean and professional-looking borders that work well in most terminal environments.

Characters used: ┌─┐│┘─└│

Source

pub const DOUBLE: Self

Creates a box using double-line Unicode box-drawing characters.

This style provides a bold, prominent appearance that’s excellent for highlighting important content or creating emphasis in CLI applications.

Characters used: ╔═╗║╝═╚║

Source

pub const ROUND: Self

Creates a box using rounded corner Unicode box-drawing characters.

This style provides a softer, more modern appearance with curved corners that’s aesthetically pleasing and less harsh than sharp corners.

Characters used: ╭─╮│╯─╰│

Source

pub const BOLD: Self

Creates a box using bold/thick line Unicode box-drawing characters.

This style provides maximum visual impact with thick, bold lines that command attention and create strong visual separation.

Characters used: ┏━┓┃┛━┗┃

Source

pub const SINGLE_DOUBLE: Self

Creates a box using single horizontal, double vertical box-drawing characters.

This mixed style combines single-line horizontal borders with double-line vertical borders, creating a unique visual effect.

Characters used: ╓─╖║╜─╙║

Source

pub const DOUBLE_SINGLE: Self

Creates a box using double horizontal, single vertical box-drawing characters.

This mixed style combines double-line horizontal borders with single-line vertical borders, creating an alternative visual effect to SINGLE_DOUBLE.

Characters used: ╒═╕│╛═╘│

Source

pub const CLASSIC: Self

Creates a box using classic ASCII characters for maximum compatibility.

This style uses only basic ASCII characters, ensuring compatibility with all terminal environments, including those that don’t support Unicode.

Characters used: +-+|+-+|

Source

pub const ARROW: Self

Creates a decorative box using arrow Unicode characters.

This unique style uses directional arrows to create an unconventional but eye-catching border effect. Best used for special emphasis or creative CLI applications.

Characters used: ↘↓↙←↖↑↗→

Source

pub const fn new( top_left: char, top: char, top_right: char, right: char, bottom_right: char, bottom: char, bottom_left: char, left: char, ) -> Self

Creates a new BoxChars with the specified characters.

§Arguments
  • top_left - Top-left corner character
  • top - Top border character
  • top_right - Top-right corner character
  • right - Right border character
  • bottom_right - Bottom-right corner character
  • bottom - Bottom border character
  • bottom_left - Bottom-left corner character
  • left - Left border character
§Examples
use cli_boxes::BoxChars;

let custom = BoxChars::new('*', '-', '*', '|', '*', '-', '*', '|');
assert_eq!(custom.top_left, '*');
assert_eq!(custom.top, '-');
Source

pub fn builder() -> BoxCharsBuilder

Creates a builder for constructing custom box characters.

§Examples
use cli_boxes::BoxChars;

let custom = BoxChars::builder()
    .corners('*')
    .horizontal('-')
    .vertical('|')
    .build();

Trait Implementations§

Source§

impl Clone for BoxChars

Source§

fn clone(&self) -> BoxChars

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 BoxChars

Source§

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

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

impl Default for BoxChars

Source§

fn default() -> Self

Returns the default box characters (single-line style).

§Examples
use cli_boxes::BoxChars;

let default_box = BoxChars::default();
assert_eq!(default_box, BoxChars::SINGLE);
Source§

impl<'de> Deserialize<'de> for BoxChars

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for BoxChars

Source§

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

Formats the box characters as a string showing all 8 characters in order.

The format is: top_left, top, top_right, right, bottom_right, bottom, bottom_left, left

§Examples
use cli_boxes::BoxChars;

let single = BoxChars::SINGLE;
println!("{}", single); // Outputs: ┌─┐│┘─└│
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 Hash for BoxChars

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 PartialEq for BoxChars

Source§

fn eq(&self, other: &BoxChars) -> 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 Serialize for BoxChars

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for BoxChars

Source§

impl Eq for BoxChars

Source§

impl StructuralPartialEq for BoxChars

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,