pub fn string(&mut self) -> Result<String> {
        // If we have a limit, then don't search further than we need to.
        let slice = match self.limit {
            Some(limit) => &self.bytes[self.offset..(self.offset + limit * WORD_NUM_BYTES)],
            None => &self.bytes[self.offset..],
        };
        // Find the null terminator.
        let first_null_byte =
            slice
                .iter()
                .position(|&c| c == 0)
                .ok_or_else(|| match self.limit {
                    Some(_) => Error::LimitReached(self.offset + slice.len()),
                    None => Error::StreamExpected(self.offset),
                })?;
        // Validate the string is utf8.
        let result = str::from_utf8(&slice[..first_null_byte])
            .map_err(|e| Error::DecodeStringFailed(self.offset, format!("{}", e)))?;
        // Round up consumed words to include null byte(s).
        let consumed_words = (first_null_byte / WORD_NUM_BYTES) + 1;
        self.offset += consumed_words * WORD_NUM_BYTES;
        if let Some(ref mut limit) = self.limit {
            // This is guaranteed to be enough due to the slice limit above.
            *limit -= consumed_words;
        }
        Ok(result.to_string())
    }
/// Decodes and returns a literal string.
///
/// This method will consume as many words as necessary until finding a
/// null character (`\0`), or reaching the limit or end of the stream
/// and erroring out.
Decodes and returns a literal string.
This method will consume as many words as necessary until finding a
null character (`\0`), or reaching the limit or end of the stream
and erroring out.
Decodes and returns a literal string . This method will consume as many words as necessary until finding a null character ( ` \ 0 ` ) or reaching the limit or end of the stream and erroring out .
pub fn string(&mut self) -> Result<String> {
        // If we have a limit, then don't search further than we need to.
        let slice = match self.limit {
            Some(limit) => &self.bytes[self.offset..(self.offset + limit * WORD_NUM_BYTES)],
            None => &self.bytes[self.offset..],
        };
        // Find the null terminator.
        let first_null_byte =
            slice
                .iter()
                .position(|&c| c == 0)
                .ok_or_else(|| match self.limit {
                    Some(_) => Error::LimitReached(self.offset + slice.len()),
                    None => Error::StreamExpected(self.offset),
                })?;
        // Validate the string is utf8.
        let result = str::from_utf8(&slice[..first_null_byte])
            .map_err(|e| Error::DecodeStringFailed(self.offset, format!("{}", e)))?;
        // Round up consumed words to include null byte(s).
        let consumed_words = (first_null_byte / WORD_NUM_BYTES) + 1;
        self.offset += consumed_words * WORD_NUM_BYTES;
        if let Some(ref mut limit) = self.limit {
            // This is guaranteed to be enough due to the slice limit above.
            *limit -= consumed_words;
        }
        Ok(result.to_string())
    }
pub fn string ( & mut self ) -> Result < String > { // If we have a limit, then don't search further than we need to. let slice = match self . limit { Some ( limit ) => & self . bytes [ self . offset .. ( self . offset + limit * WORD_NUM_BYTES ) ] , None => & self . bytes [ self . offset .. ] , } ; // Find the null terminator. let first_null_byte = slice . iter ( ) . position ( | & c | c == 0 ) . ok_or_else ( | | match self . limit { Some ( _ ) => Error :: LimitReached ( self . offset + slice . len ( ) ) , None => Error :: StreamExpected ( self . offset ) , } ) ? ; // Validate the string is utf8. let result = str :: from_utf8 ( & slice [ .. first_null_byte ] ) . map_err ( | e | Error :: DecodeStringFailed ( self . offset , format ! ( " " e ) ) ) ? ; // Round up consumed words to include null byte(s). let consumed_words = ( first_null_byte / WORD_NUM_BYTES ) + 1 ; self . offset += consumed_words * WORD_NUM_BYTES ; if let Some ( ref mut limit ) = self . limit { // This is guaranteed to be enough due to the slice limit above. * limit -= consumed_words ; } Ok ( result . to_string ( ) ) }
Decodes and returns a literal string.
Decodes and returns a literal string .
&mut self
&mut self