codeq/codec/decode.rs
1use std::io;
2
3/// A trait that can be decoded from an [`io::Read`] stream.
4///
5/// Implementing this trait allows types to be decoded from an [`io::Read`] stream,
6/// which is useful for reading data from various sources like files, buffers, and streams.
7///
8/// # Examples
9/// ```rust
10/// use codeq::Decode;
11///
12/// let data = b"\x00\x00\x00\x05hello";
13/// let decoded = String::decode(&data[..]).unwrap();
14/// assert_eq!(decoded, "hello");
15/// ```
16pub trait Decode: Sized {
17 fn decode<R: io::Read>(r: R) -> Result<Self, io::Error>;
18}