Skip to main content

ReaderSegments

Trait ReaderSegments 

Source
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§

Source

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§

Source

fn len(&self) -> usize

Gets the number of segments.

Source

fn is_empty(&self) -> bool

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>
where I: AsRef<[u8]>,

Available on crate feature alloc only.
Source§

fn get_segment(&self, id: u32) -> Option<&[u8]>

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<I> ReaderSegments for [I]
where I: AsRef<[u8]>,

Source§

fn get_segment(&self, id: u32) -> Option<&[u8]>

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<S> ReaderSegments for &S
where 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());
Source§

fn get_segment(&self, idx: u32) -> Option<&[u8]>

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Implementors§

Source§

impl ReaderSegments for OutputSegments<'_>

Source§

impl ReaderSegments for OwnedSegments

Available on crate feature alloc only.
Source§

impl ReaderSegments for SegmentArray<'_>

Source§

impl<A> ReaderSegments for Builder<A>
where A: Allocator,

Source§

impl<T: AsRef<[u8]>> ReaderSegments for NoAllocBufferSegments<T>

Source§

impl<T: Deref<Target = [u8]>> ReaderSegments for BufferSegments<T>

Available on crate feature alloc only.