/// Write given data into the buffer.
Write given data into the buffer.
Write given data into the buffer .
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
        // expand buffer if needed
        let buf_capacity = self.buffer.capacity();
        if (self.used + data.len()) > buf_capacity {
            // TODO: replace this with resize (after it's stabilized)
            self.buffer.reserve(self.used + data.len() - buf_capacity);
            let buf_capacity = self.buffer.capacity();
            unsafe {
                self.buffer.set_len(buf_capacity);
            }
        }
        // shift the buffered data to the left if needed
        let buf_capacity = self.buffer.capacity();
        if (self.offset + self.used + data.len()) > buf_capacity {
            let dst = self.buffer.as_mut_ptr();
            unsafe {
                let src = dst.offset(self.offset as isize);
                ptr::copy(src, dst, self.used); 
            }
            self.offset = 0;
        }
        // write given data
        let offset     = self.offset + self.used;
        let mut buffer = &mut self.buffer[offset..];
        buffer.write_all(data)
            .unwrap();
        self.used += data.len();
        Ok(data.len())
    }
fn write ( & mut self , data : & [ u8 ] ) -> io :: Result < usize > { // expand buffer if needed let buf_capacity = self . buffer . capacity ( ) ; if ( self . used + data . len ( ) ) > buf_capacity { // TODO: replace this with resize (after it's stabilized) self . buffer . reserve ( self . used + data . len ( ) - buf_capacity ) ; let buf_capacity = self . buffer . capacity ( ) ; unsafe { self . buffer . set_len ( buf_capacity ) ; } } // shift the buffered data to the left if needed let buf_capacity = self . buffer . capacity ( ) ; if ( self . offset + self . used + data . len ( ) ) > buf_capacity { let dst = self . buffer . as_mut_ptr ( ) ; unsafe { let src = dst . offset ( self . offset as isize ) ; ptr :: copy ( src , dst , self . used ) ; } self . offset = 0 ; } // write given data let offset = self . offset + self . used ; let mut buffer = & mut self . buffer [ offset .. ] ; buffer . write_all ( data ) . unwrap ( ) ; self . used += data . len ( ) ; Ok ( data . len ( ) ) }
Write given data into the buffer.
Write given data into the buffer .
&mut self
data
&[u8]