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: charTop-left corner character
top: charTop border character (repeated horizontally)
top_right: charTop-right corner character
right: charRight border character (repeated vertically)
bottom_right: charBottom-right corner character
bottom: charBottom border character (repeated horizontally)
bottom_left: charBottom-left corner character
left: charLeft border character (repeated vertically)
Implementations§
Source§impl BoxChars
impl BoxChars
Sourcepub const NONE: Self
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.
Sourcepub const SINGLE: Self
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: ┌─┐│┘─└│
Sourcepub const DOUBLE: Self
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: ╔═╗║╝═╚║
Sourcepub const ROUND: Self
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: ╭─╮│╯─╰│
Sourcepub const BOLD: Self
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: ┏━┓┃┛━┗┃
Sourcepub const SINGLE_DOUBLE: Self
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: ╓─╖║╜─╙║
Sourcepub const DOUBLE_SINGLE: Self
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: ╒═╕│╛═╘│
Sourcepub const CLASSIC: Self
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: +-+|+-+|
Sourcepub const ARROW: Self
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: ↘↓↙←↖↑↗→
Sourcepub const fn new(
top_left: char,
top: char,
top_right: char,
right: char,
bottom_right: char,
bottom: char,
bottom_left: char,
left: char,
) -> Self
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 charactertop- Top border charactertop_right- Top-right corner characterright- Right border characterbottom_right- Bottom-right corner characterbottom- Bottom border characterbottom_left- Bottom-left corner characterleft- Left border character
§Examples
use cli_boxes::BoxChars;
let custom = BoxChars::new('*', '-', '*', '|', '*', '-', '*', '|');
assert_eq!(custom.top_left, '*');
assert_eq!(custom.top, '-');Sourcepub fn builder() -> BoxCharsBuilder
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<'de> Deserialize<'de> for BoxChars
impl<'de> Deserialize<'de> for BoxChars
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for BoxChars
impl Display for BoxChars
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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
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);