Expand description
§Cap’n Proto Runtime Library
This crate contains basic facilities for reading and writing Cap’n Proto messages in Rust. It is intended to be used in conjunction with code generated by the capnpc-rust crate.
§type newtypes
A schema type declaration is a newtype. A scalar newtype (type Uuid = Data) generates a
module of transparent Reader/Builder/Owned aliases – wire-identical to the underlying
type, preserving only the name. An inline group or union newtype
(type Vec3 = group { x @0 :Float32; ... }, stamped into a struct at explicit @[...] ordinals
so it shares the parent’s space with no pointer indirection) generates a module containing:
Reader/Buildertraits – the newtype’s shared interface. Each use site is a distinct concrete type (with its offsets baked in), and all of them implement these traits, so animpl vec3::Reader/impl vec3::Builderbound lets you write code generic over every use site. A union newtype’sReaderadditionally haswhich(), returning a sharedWhichenum.AnyReader/AnyBuilder– a single erased type spanning use sites, reading field offsets from a runtime table (built with a concrete accessor’sas_any()). Use them where one type must span use sites – aVec, a return type, a struct field. A per-use-site concrete type can’t do that, and neither can&dynonce the newtype nests another newtype or is a union (those need associated types, which are not object-safe). The erased carriers mirror Cap’n Proto’s C++AnyReader/AnyBuilder, keeping the two languages’ generated APIs consistent – a primary motivation for this design.
An incomplete @[...] mapping may leave trailing fields unmapped; an unmapped field reads its
default, and setting one panics ("... is not mapped at this use site") – mirroring the C++
codegen’s behavior.
Modules§
- any_
pointer - Untyped pointer that can be cast to any struct, list, or capability type.
- any_
pointer_ list - List of AnyPointers.
- capability
- Hooks for the RPC system.
- capability_
list - List of capabilities.
- constant
- Helper type for generated Struct and List constants.
- data
- Sequence of bytes.
- data_
list - List of sequences of bytes.
- dynamic_
list - Dynamically-typed lists.
- dynamic_
struct - Dynamically-typed structs.
- dynamic_
value - Dynamically typed values.
- enum_
list - List of enums.
- introspect
- Traits and types to support run-time type introspection, i.e. reflection.
- io
- Custom I/O traits that roughly mirror
std::io::{Read, BufRead, Write}. This extra layer of indirection enables support of no-std environments. - list_
list - List of lists.
- message
- Untyped root container for a Cap’n Proto value.
- primitive_
list - List of primitives.
- private
- Implementation details that should never be directly used by clients.
- raw
- Functions providing low level access to encoded data.
- schema
- Convenience wrappers of the datatypes defined in schema.capnp.
- schema_
capnp - Code generated from schema.capnp.
- serialize
- Reading and writing of messages using the standard stream framing.
- serialize_
packed - Reading and writing of messages using the packed stream encoding.
- struct_
list - List of structs.
- text
- UTF-8 encoded text.
- text_
list - List of strings containing UTF-8 encoded text.
- traits
Macros§
- generated_
code - Macro for importing Rust code that has been generated by
capnpc::CompilerCommand.
Structs§
- Error
- Describes an arbitrary error that prevented an operation from completing.
- Message
Size - Size of a message. Every generated struct has a method
.total_size()that returns this. - NotIn
Schema - An enum value or union discriminant that was not found among those defined in a schema.
- Word
- 8 bytes, aligned to an 8-byte boundary.
Enums§
- Error
Kind - The general nature of an error. The purpose of this enum is not to describe the error itself, but rather to describe how the client might want to respond to the error.
- Output
Segments - Helper struct that allows
MessageBuilder::get_segments_for_output()to avoid heap allocations in the single-segment case.
Functions§
- word
- Constructs a word with the given bytes.
Type Aliases§
- Result
- Because messages are lazily validated, the return type of any method that reads a pointer field must be wrapped in a Result.