fn with_padding<F>(&mut self, padding: usize, default: Alignment,
                       f: F) -> Result
        where F: FnOnce(&mut Formatter) -> Result,
    {
        use char::CharExt;
        let align = match self.align {
            Alignment::Unknown => default,
            _ => self.align
        };

        let (pre_pad, post_pad) = match align {
            Alignment::Left => (0, padding),
            Alignment::Right | Alignment::Unknown => (padding, 0),
            Alignment::Center => (padding / 2, (padding + 1) / 2),
        };

        let mut fill = [0; 4];
        let len = self.fill.encode_utf8(&mut fill).unwrap_or(0);
        let fill = unsafe { str::from_utf8_unchecked(&fill[..len]) };

        for _ in 0..pre_pad {
            try!(self.buf.write_str(fill));
        }

        try!(f(self));

        for _ in 0..post_pad {
            try!(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.
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: Alignment,
                       f: F) -> Result
        where F: FnOnce(&mut Formatter) -> Result,
    {
        use char::CharExt;
        let align = match self.align {
            Alignment::Unknown => default,
            _ => self.align
        };
        let (pre_pad, post_pad) = match align {
            Alignment::Left => (0, padding),
            Alignment::Right | Alignment::Unknown => (padding, 0),
            Alignment::Center => (padding / 2, (padding + 1) / 2),
        };
        let mut fill = [0; 4];
        let len = self.fill.encode_utf8(&mut fill).unwrap_or(0);
        let fill = unsafe { str::from_utf8_unchecked(&fill[..len]) };
        for _ in 0..pre_pad {
            try!(self.buf.write_str(fill));
        }
        try!(f(self));
        for _ in 0..post_pad {
            try!(self.buf.write_str(fill));
        }
        Ok(())
    }
fn with_padding < F > ( & mut self , padding : usize , default : Alignment , f : F ) -> Result where F : FnOnce ( & mut Formatter ) -> Result , { use char :: CharExt ; let align = match self . align { Alignment :: Unknown => default , _ => self . align } ; let ( pre_pad , post_pad ) = match align { Alignment :: Left => ( 0 , padding ) , Alignment :: Right | Alignment :: Unknown => ( padding , 0 ) , Alignment :: Center => ( padding / 2 , ( padding + 1 ) / 2 ) , } ; let mut fill = [ 0 ; 4 ] ; let len = self . fill . encode_utf8 ( & mut fill ) . unwrap_or ( 0 ) ; let fill = unsafe { str :: from_utf8_unchecked ( & fill [ .. len ] ) } ; for _ in 0 .. pre_pad { try ! ( self buf write_str ( fill ) ) ; } try ! ( f ( self ) ) ; for _ in 0 .. post_pad { try ! ( 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
Alignment
f
F