pub enum Alignment {
Left,
Center,
Right,
}
Expand description
Specifies the alignment direction for text.
This enum defines the three fundamental alignment options available in the library. Each variant represents a different strategy for positioning text within the available width.
§Alignment Behavior
Left
: Text is positioned at the leftmost edge (no padding on left)Center
: Text is centered with equal padding on both sidesRight
: Text is positioned at the rightmost edge (padding on left)
§Performance Notes
Left
alignment is optimized as a no-op operationCenter
andRight
alignments require width calculation and padding
§Examples
§Basic Usage
use ansi_align::{Alignment, AlignOptions, ansi_align_with_options};
let text = "hello\nworld";
// Center alignment - distributes padding evenly
let opts = AlignOptions::new(Alignment::Center);
let result = ansi_align_with_options(text, &opts);
// Result: " hello\nworld" (hello gets 1 space padding)
// Right alignment - adds all padding to the left
let opts = AlignOptions::new(Alignment::Right);
let result = ansi_align_with_options(text, &opts);
// Result: " hello\n world" (both lines right-aligned)
// Left alignment - no changes to input
let opts = AlignOptions::new(Alignment::Left);
let result = ansi_align_with_options(text, &opts);
// Result: "hello\nworld" (unchanged)
§With Custom Padding
use ansi_align::{Alignment, AlignOptions, ansi_align_with_options};
let text = "short\nlonger";
let opts = AlignOptions::new(Alignment::Right).with_pad('.');
let result = ansi_align_with_options(text, &opts);
// Result: ".short\nlonger"
Variants§
Left
Align text to the left (no padding added to the left side)
Center
Align text to the center (padding distributed evenly on both sides)
Right
Align text to the right (padding added to the left side)
Trait Implementations§
impl Copy for Alignment
impl Eq for Alignment
impl StructuralPartialEq for Alignment
Auto Trait Implementations§
impl Freeze for Alignment
impl RefUnwindSafe for Alignment
impl Send for Alignment
impl Sync for Alignment
impl Unpin for Alignment
impl UnwindSafe for Alignment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more