/// Runs a callback, emitting the correct padding either before or
/// afterwards depending on whether right or left alignment is requested.
Runs a callback, emitting the correct padding either before or
afterwards depending on whether right or left alignment is requested.
Runs a callback emitting the correct padding either before or afterwards depending on whether right or left alignment is requested .
fn with_padding<F>(&mut self, padding: usize, default: rt::v1::Alignment,
                       f: F) -> Result
        where F: FnOnce(&mut Formatter) -> Result,
    {
        use char::CharExt;
        let align = match self.align {
            rt::v1::Alignment::Unknown => default,
            _ => self.align
        };
        let (pre_pad, post_pad) = match align {
            rt::v1::Alignment::Left => (0, padding),
            rt::v1::Alignment::Right |
            rt::v1::Alignment::Unknown => (padding, 0),
            rt::v1::Alignment::Center => (padding / 2, (padding + 1) / 2),
        };
        let fill = self.fill.encode_utf8();
        let fill = unsafe {
            str::from_utf8_unchecked(fill.as_slice())
        };
        for _ in 0..pre_pad {
            self.buf.write_str(fill)?;
        }
        f(self)?;
        for _ in 0..post_pad {
            self.buf.write_str(fill)?;
        }
        Ok(())
    }
fn with_padding < F > ( & mut self , padding : usize , default : rt :: v1 :: Alignment , f : F ) -> Result where F : FnOnce ( & mut Formatter ) -> Result , { use char :: CharExt ; let align = match self . align { rt :: v1 :: Alignment :: Unknown => default , _ => self . align } ; let ( pre_pad , post_pad ) = match align { rt :: v1 :: Alignment :: Left => ( 0 , padding ) , rt :: v1 :: Alignment :: Right | rt :: v1 :: Alignment :: Unknown => ( padding , 0 ) , rt :: v1 :: Alignment :: Center => ( padding / 2 , ( padding + 1 ) / 2 ) , } ; let fill = self . fill . encode_utf8 ( ) ; let fill = unsafe { str :: from_utf8_unchecked ( fill . as_slice ( ) ) } ; for _ in 0 .. pre_pad { self . buf . write_str ( fill ) ? ; } f ( self ) ? ; for _ in 0 .. post_pad { self . buf . write_str ( fill ) ? ; } Ok ( ( ) ) }
Runs a callback, emitting the correct padding either before or
afterwards depending on whether right or left alignment is requested.
Runs a callback emitting the correct padding either before or afterwards depending on whether right or left alignment is requested .
&mut self
padding
usize
default
rt::v1::Alignment
f
F