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:
- if any IO error (including unexpected EOF) occurs, while reading an
rd
, except the EINTR, which is handled internally. - if the
out
buffer size is not large enough to keep all the data copyed. - if the data is not utf-8, with a description as to why the provided data is not utf-8 and
with a size of bytes actually copyed to be able to get them from
out
.
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.