pub type Result<T> = Result<T, Error>;
Expand description
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.
§Examples
Trying to decode a string from raw bytes:
use core::str::{self, Utf8Error};
use byteio::WriteBytes;
fn decode_str(buf: &[u8]) -> Result<&str, Utf8Error> {
str::from_utf8(buf)
}
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),
}
Ok(())
}
Aliased Type§
enum Result<T> {
Ok(T),
Err(Error),
}