pub trait ReaderSegments {
// Required method
fn get_segment(&self, idx: u32) -> Option<&[u8]>;
// Provided methods
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
}Expand description
An object that manages the buffers underlying a Cap’n Proto message reader.
Required Methods§
Sourcefn get_segment(&self, idx: u32) -> Option<&[u8]>
fn get_segment(&self, idx: u32) -> Option<&[u8]>
Gets the segment with index idx. Returns None if idx is out of range.
The segment must be 8-byte aligned or the “unaligned” feature must be enabled in the capnp crate. (Otherwise reading the segment will return an error.)
The returned slice is required to point to memory that remains valid until the ReaderSegments object is dropped. In safe Rust, it should not be possible to violate this requirement.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<I> ReaderSegments for Vec<I>
Available on crate feature alloc only.
impl<I> ReaderSegments for Vec<I>
alloc only.Source§impl<I> ReaderSegments for [I]
impl<I> ReaderSegments for [I]
Source§impl<S> ReaderSegments for &Swhere
S: ReaderSegments + ?Sized,
Allows stacking of references to a ReaderSegments.
impl<S> ReaderSegments for &Swhere
S: ReaderSegments + ?Sized,
Allows stacking of references to a ReaderSegments.
This is especially useful with the implementation for slices, as it allows treating
&[&[u8]] as ReaderSegments, e.g., to construct a Reader:
use capnp::message::Reader;
let slice_of_slices: &[&[u8]] = &[&*b"some data", &*b"more data"];
let _ = Reader::new(slice_of_slices, Default::default());Implementors§
impl ReaderSegments for OutputSegments<'_>
impl ReaderSegments for OwnedSegments
alloc only.impl ReaderSegments for SegmentArray<'_>
impl<A> ReaderSegments for Builder<A>where
A: Allocator,
impl<T: AsRef<[u8]>> ReaderSegments for NoAllocBufferSegments<T>
impl<T: Deref<Target = [u8]>> ReaderSegments for BufferSegments<T>
alloc only.