Module container

Module container 

Source
Expand description

Traits for Rust representations of Protobuf string, bytes, repeated, and map fields.

In order to represent string, bytes, repeated, and map fields in Rust, multi-element containers are needed. To ensure flexibility, micropb interfaces with containers using traits from this module rather than hard-coded types. This allows compatibility with different container implementations. For example, no-std users can use fixed-capacity containers from heapless or arrayvec, and alloc users can use dynamic-capacity containers from the standard library.

For convenience, container trait implementations on existing types are provided in this module, gated by feature flags.

  • For heapless, PbString, PbBytes, PbVec, and PbMap are implemented on heapless::String, heapless::Vec, and heapless::IndexMap.
  • For arrayvec, PbString, PbBytes, and PbVec are implemented on arrayvec::ArrayString and arrayvec::ArrayVec.
  • For alloc, PbString, PbBytes, PbVec, and PbMap are implemented on String, Vec, and BTreeMap. If std is enabled, PbMap is also implemented for HashMap.

It is also possible to use other types as containers if the container traits are implemented.

Traitsยง

PbBytes
Container that stores a sequence of arbitrary bytes. Represents Protobuf bytes field.
PbMap
Map that stores key-value pairs. Represents Protobuf map field.
PbString
Container that stores a string. Represents Protobuf string field.
PbVec
Generic vector that stores multiple elements. Represents repeated field.