Expand description
Untyped root container for a Cap’n Proto value.
§Notes about type specialization
This module provides TypedReader and TypedBuilder structs which are strongly-typed variants of Reader and Builder.
Code autogenerated by capnpc will have an individual module for each structure and each of these
modules will have Owned struct which implements Owned trait.
Example from a real auto-generated file:
ⓘ
pub mod simple_struct {
#[derive(Copy, Clone)]
pub struct Owned(());
impl <'a> ::capnp::traits::Owned<'a> for Owned { type Reader = Reader<'a>; type Builder = Builder<'a>; }
....
}TypedReader and TypedBuilder accept generic type parameter T. This parameter must be
a corresponding Owned type which was auto-generated inside the corresponding module.
For example, for auto-generated module crate::test_data::simple_struct you’d supply
crate::test_data::simple_struct::Owned type into TypedReader/TypedBuilder
ⓘ
capnp::generated_code!(mod simple_struct_capnp);
use capnp::message::{self, TypedBuilder, TypedReader};
use simple_struct_capnp::simple_struct;
fn main() {
let mut builder = TypedBuilder::<simple_struct::Owned>::new_default();
let mut builder_root = builder.init_root();
builder_root.set_x(10);
builder_root.set_y(20);
let mut buffer = vec![];
capnp::serialize_packed::write_message(&mut buffer, builder.borrow_inner()).unwrap();
let reader = capnp::serialize_packed::read_message(buffer.as_slice(), ReaderOptions::new()).unwrap();
let typed_reader = TypedReader::<_, simple_struct::Owned>::new(reader);
let reader_root = typed_reader.get().unwrap();
assert_eq!(reader_root.get_x(), 10);
assert_eq!(reader_root.get_y(), 20);
}
Structs§
- Builder
- A container used to build a message.
- Heap
Allocator - Standard segment allocator. Allocates each segment via
alloc::alloc::alloc_zeroed(). - Reader
- A container used to read a message.
- Reader
Options - Options controlling how data is read.
- Scratch
Space Heap Allocator - An Allocator whose first segment is backed by a user-provided buffer.
- Segment
Array - An array of segments.
- Single
Segment Allocator - An Allocator whose first and only segment is backed by a user-provided buffer. If the segment fills up, subsequent allocations trigger panics.
- Typed
Builder - Strongly typed variant of the Builder
- Typed
Reader - A message reader whose value is known to be of type
T. Please see module documentation for more info about reader type specialization.
Enums§
Constants§
Traits§
- Allocator
- An object that allocates memory for a Cap’n Proto message as it is being built.
- Reader
Segments - An object that manages the buffers underlying a Cap’n Proto message reader.