Trait zero_copy_pads::ExcessHandler [−][src]
pub trait ExcessHandler<Value, PadBlock = char> where
Value: Width,
PadBlock: Display, { fn handle_excess(
&self,
excess: Excess<'_, Value, PadBlock>,
formatter: &mut Formatter<'_>
) -> Result<(), Error>; }
What to do when the width of the value exceeds total.
Example: Truncate to make it fit
use zero_copy_pads::{ExcessHandler, Excess, PaddedValue, AlignRight}; use std::fmt::{Formatter, Result}; struct TruncateExcessiveString; impl ExcessHandler<&str> for TruncateExcessiveString { fn handle_excess(&self, excess: Excess<&str>, formatter: &mut Formatter<'_>) -> Result { let mut value = excess.value.to_string(); value.truncate(excess.total_width); write!(formatter, "{}", value) } } let padded_value = PaddedValue { handle_excess: TruncateExcessiveString, value: "abcdefghi", total_width: 4, pad_block: ' ', pad: AlignRight, }; assert_eq!(padded_value.to_string(), "abcd");
Required methods
fn handle_excess(
&self,
excess: Excess<'_, Value, PadBlock>,
formatter: &mut Formatter<'_>
) -> Result<(), Error>
[src]
&self,
excess: Excess<'_, Value, PadBlock>,
formatter: &mut Formatter<'_>
) -> Result<(), Error>
Handle excessive width of a value.
Implementors
impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for ErrorOnExcess where
Value: Width,
PadBlock: Display,
[src]
impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for ErrorOnExcess where
Value: Width,
PadBlock: Display,
[src]impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for ExcessHandlingFunction<Value, PadBlock> where
Value: Width,
PadBlock: Display,
[src]
impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for ExcessHandlingFunction<Value, PadBlock> where
Value: Width,
PadBlock: Display,
[src]impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for IgnoreExcess where
Value: Width,
PadBlock: Display,
[src]
impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for IgnoreExcess where
Value: Width,
PadBlock: Display,
[src]impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for PanicOnExcess where
Value: Width,
PadBlock: Display,
[src]
impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for PanicOnExcess where
Value: Width,
PadBlock: Display,
[src]