Function rmp::decode::read_str [] [src]

pub fn read_str<'r, R>(rd: &mut R, buf: &'r mut [u8]) -> Result<&'r str, DecodeStringError<'r>> where R: Read
[]

Attempts to read a string data from the given reader and copy it to the buffer provided.

On success returns a borrowed string type, allowing to view the copyed bytes as properly utf-8 string. According to the spec, the string's data must to be encoded using utf-8.

Errors

Returns Err in the following cases:

Examples

use rmp::decode::read_str;

let buf = [0xaa, 0x6c, 0x65, 0x20, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65];
let mut out = [0u8; 16];

assert_eq!("le message", read_str(&mut &buf[..], &mut &mut out[..]).unwrap());

Unstable

This function is unstable, because it needs review.

Note

This function will silently retry on every EINTR received from the underlying Read until successful read.