pub enum Alignment {
Left,
Right,
CenterLeft,
CenterRight,
}
Expand description
Where the place the pad blocks.
Variants§
Left
Pad to the right, content to the left.
Example:
use zero_copy_pads::{Alignment::Left, PaddedValue, PanicOnExcess};
let padded_value = PaddedValue {
pad: Left,
value: "abcdef",
pad_block: '-',
total_width: 9,
handle_excess: PanicOnExcess,
};
assert_eq!(padded_value.to_string(), "abcdef---");
Right
Pad to the left, content to the right.
Example:
use zero_copy_pads::{Alignment::Right, PaddedValue, PanicOnExcess};
let padded_value = PaddedValue {
pad: Right,
value: "abcdef",
pad_block: '-',
total_width: 9,
handle_excess: PanicOnExcess,
};
assert_eq!(padded_value.to_string(), "---abcdef");
CenterLeft
Pad to both sides, place content in the middle, but shift to the left one block if it can’t be exactly central.
Example:
use zero_copy_pads::{Alignment::CenterLeft, PaddedColumn, PanicOnExcess};
let values = [
"Rust", "C", "C++", "C#", "JavaScript",
"TypeScript", "Java", "Kotlin", "Go",
];
let padded_column = PaddedColumn {
pad: CenterLeft,
values: values.iter(),
pad_block: '-',
};
let padded_values: Vec<_> = padded_column
.into_iter()
.map(|x| x.to_string())
.collect();
let expected = [
"---Rust---", "----C-----", "---C++----",
"----C#----", "JavaScript", "TypeScript",
"---Java---", "--Kotlin--", "----Go----",
];
assert_eq!(padded_values, expected);
CenterRight
Pad to both sides, place content in the middle, but shift to the right one block if it can’t be exactly central.
Example:
use zero_copy_pads::{Alignment::CenterRight, PaddedColumn, PanicOnExcess};
let values = [
"Rust", "C", "C++", "C#", "JavaScript",
"TypeScript", "Java", "Kotlin", "Go",
];
let padded_column = PaddedColumn {
pad: CenterRight,
values: values.iter(),
pad_block: '-',
};
let padded_values: Vec<_> = padded_column
.into_iter()
.map(|x| x.to_string())
.collect();
let expected = [
"---Rust---", "-----C----", "----C++---",
"----C#----", "JavaScript", "TypeScript",
"---Java---", "--Kotlin--", "----Go----",
];
assert_eq!(padded_values, expected);
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more