pub struct ExcessHandlingFunction<Value, PadBlock = char>(pub fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>)
where
Value: Width,
PadBlock: Display;
Expand description
Turn a function (without closure) into a ExcessHandler
.
Example: Truncate to make it fit
use zero_copy_pads::{ExcessHandlingFunction, Excess, PaddedValue, AlignRight};
use std::fmt::{Formatter, Result};
let truncate = ExcessHandlingFunction::<&str>(|excess, formatter| {
let mut value = excess.value.to_string();
value.truncate(excess.total_width);
write!(formatter, "{}", value)
});
let padded_value = PaddedValue {
handle_excess: truncate,
value: "abcdefghi",
total_width: 4,
pad_block: ' ',
pad: AlignRight,
};
assert_eq!(padded_value.to_string(), "abcd");
Tuple Fields§
§0: fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>
Trait Implementations§
Source§impl<Value, PadBlock> AsMut<fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> AsMut<fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>> for ExcessHandlingFunction<Value, PadBlock>
Source§impl<Value, PadBlock> AsRef<fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> AsRef<fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>> for ExcessHandlingFunction<Value, PadBlock>
Source§impl<Value, PadBlock> Clone for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> Clone for ExcessHandlingFunction<Value, PadBlock>
Source§fn clone(&self) -> ExcessHandlingFunction<Value, PadBlock>
fn clone(&self) -> ExcessHandlingFunction<Value, PadBlock>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<Value, PadBlock> Deref for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> Deref for ExcessHandlingFunction<Value, PadBlock>
Source§impl<Value, PadBlock> DerefMut for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> DerefMut for ExcessHandlingFunction<Value, PadBlock>
Source§impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> ExcessHandler<Value, PadBlock> for ExcessHandlingFunction<Value, PadBlock>
Source§impl<Value, PadBlock> From<ErrorOnExcess> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> From<ErrorOnExcess> for ExcessHandlingFunction<Value, PadBlock>
Source§fn from(_: ErrorOnExcess) -> Self
fn from(_: ErrorOnExcess) -> Self
Converts to this type from the input type.
Source§impl<Value, PadBlock> From<IgnoreExcess> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> From<IgnoreExcess> for ExcessHandlingFunction<Value, PadBlock>
Source§fn from(_: IgnoreExcess) -> Self
fn from(_: IgnoreExcess) -> Self
Converts to this type from the input type.
Source§impl<Value, PadBlock> From<PanicOnExcess> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> From<PanicOnExcess> for ExcessHandlingFunction<Value, PadBlock>
Source§fn from(_: PanicOnExcess) -> Self
fn from(_: PanicOnExcess) -> Self
Converts to this type from the input type.
Source§impl<Value, PadBlock> From<fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> From<fn(Excess<'_, Value, PadBlock>, &mut Formatter<'_>) -> Result<(), Error>> for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> Copy for ExcessHandlingFunction<Value, PadBlock>
Auto Trait Implementations§
impl<Value, PadBlock> Freeze for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> RefUnwindSafe for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> Send for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> Sync for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> Unpin for ExcessHandlingFunction<Value, PadBlock>
impl<Value, PadBlock> UnwindSafe for ExcessHandlingFunction<Value, PadBlock>
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