[][src]Type Definition byteio::Result

type Result<T> = Result<T, Error>;

A specialized Result type for byteio operations.

This type alias is broadly used across byteio for operations that may produce an error, that is, overflow the underlying buffer.

As with std::io::Result, it is not recommended to import this type directly and shadow core::result::Result, but instead to use byteio::Result to make it easier to distinguish.


Trying to decode a string from raw bytes:

use core::str::{self, Utf8Error};

use byteio::WriteBytes;

fn decode_str(buf: &[u8]) -> Result<&str, Utf8Error> {

fn main() -> byteio::Result<()> {
    let mut buf = [0; 5];

    (&mut buf[..]).try_write_exact(b"hello")?;

    match decode_str(&buf) {
        Ok(s) => println!("str from utf8 success!"),
        Err(e) => println!("str from utf8 failure: {}", e),