pub trait Readable<'a, C: Context>: Sized {
Show 17 methods
// Required method
fn read_from<R: Reader<'a, C>>(reader: &mut R) -> Result<Self, C::Error>;
// Provided methods
fn minimum_bytes_needed() -> usize { ... }
fn read_from_buffer(buffer: &'a [u8]) -> Result<Self, C::Error>
where Self: DefaultContext<Context = C>,
C: Default { ... }
fn read_with_length_from_buffer(
buffer: &'a [u8]
) -> (Result<Self, C::Error>, usize)
where Self: DefaultContext<Context = C>,
C: Default { ... }
fn read_from_buffer_copying_data(buffer: &[u8]) -> Result<Self, C::Error>
where Self: DefaultContext<Context = C>,
C: Default { ... }
fn read_with_length_from_buffer_copying_data(
buffer: &[u8]
) -> (Result<Self, C::Error>, usize)
where Self: DefaultContext<Context = C>,
C: Default { ... }
fn read_from_stream_unbuffered(stream: impl Read) -> Result<Self, C::Error>
where Self: DefaultContext<Context = C>,
C: Default { ... }
fn read_from_stream_buffered(stream: impl Read) -> Result<Self, C::Error>
where Self: DefaultContext<Context = C>,
C: Default { ... }
fn read_from_file(path: impl AsRef<Path>) -> Result<Self, C::Error>
where Self: DefaultContext<Context = C>,
C: Default { ... }
fn read_from_buffer_with_ctx(
context: C,
buffer: &'a [u8]
) -> Result<Self, C::Error> { ... }
fn read_with_length_from_buffer_with_ctx(
context: C,
buffer: &'a [u8]
) -> (Result<Self, C::Error>, usize) { ... }
fn read_from_buffer_copying_data_with_ctx(
context: C,
buffer: &[u8]
) -> Result<Self, C::Error> { ... }
fn read_with_length_from_buffer_copying_data_with_ctx(
context: C,
buffer: &[u8]
) -> (Result<Self, C::Error>, usize) { ... }
fn read_with_length_from_buffer_copying_data_with_ctx_mut(
context: &mut C,
buffer: &[u8]
) -> (Result<Self, C::Error>, usize) { ... }
fn read_from_stream_unbuffered_with_ctx<S: Read>(
context: C,
stream: S
) -> Result<Self, C::Error> { ... }
fn read_from_stream_buffered_with_ctx<S: Read>(
context: C,
stream: S
) -> Result<Self, C::Error> { ... }
fn read_from_file_with_ctx(
context: C,
path: impl AsRef<Path>
) -> Result<Self, C::Error> { ... }
}
Required Methods§
Provided Methods§
fn minimum_bytes_needed() -> usize
sourcefn read_from_buffer(buffer: &'a [u8]) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
fn read_from_buffer(buffer: &'a [u8]) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
Deserializes from a given buffer.
This performs zero-copy deserialization when possible.
sourcefn read_with_length_from_buffer(
buffer: &'a [u8]
) -> (Result<Self, C::Error>, usize)where
Self: DefaultContext<Context = C>,
C: Default,
fn read_with_length_from_buffer(
buffer: &'a [u8]
) -> (Result<Self, C::Error>, usize)where
Self: DefaultContext<Context = C>,
C: Default,
Deserializes from a given buffer while also returning the amount of bytes consumed.
This performs zero-copy deserialization when possible.
sourcefn read_from_buffer_copying_data(buffer: &[u8]) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
fn read_from_buffer_copying_data(buffer: &[u8]) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
Deserializes from a given buffer.
This never performs zero-copy deserialization.
sourcefn read_with_length_from_buffer_copying_data(
buffer: &[u8]
) -> (Result<Self, C::Error>, usize)where
Self: DefaultContext<Context = C>,
C: Default,
fn read_with_length_from_buffer_copying_data(
buffer: &[u8]
) -> (Result<Self, C::Error>, usize)where
Self: DefaultContext<Context = C>,
C: Default,
Deserializes from a given buffer while also returning the amount of bytes consumed.
This never performs zero-copy deserialization.
sourcefn read_from_stream_unbuffered(stream: impl Read) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
fn read_from_stream_unbuffered(stream: impl Read) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
Reads from a given stream without any buffering.
This will only read what is necessary from the stream to deserialize a given type, but is going to be slow.
Use read_from_stream_buffered
if you need
to read from a stream and you don’t care about not overreading.
sourcefn read_from_stream_buffered(stream: impl Read) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
fn read_from_stream_buffered(stream: impl Read) -> Result<Self, C::Error>where
Self: DefaultContext<Context = C>,
C: Default,
Reads from a given stream with internal buffering.
This will read more data from the stream than is necessary to deserialize a given type, however it should be orders of magnitude faster than unbuffered streaming, especially when reading relatively complex objects.
Use the slower read_from_stream_unbuffered
if you want
to avoid overreading.