Module containers

Module containers 

Source
Expand description

Collection types for protobuf messages.

This module provides arena-allocated containers used by generated protobuf code:

  • RepeatedField<T>: A growable array for repeated fields
  • String: UTF-8 string (equivalent to protobuf string)
  • Bytes: Byte array (equivalent to protobuf bytes)

These types are designed for arena allocation and do not implement Drop. Memory is freed when the arena is dropped.

§Example

use protocrap::{arena::Arena, containers::{RepeatedField, String}};
use allocator_api2::alloc::Global;

let mut arena = Arena::new(&Global);

// RepeatedField for integers
let mut numbers = RepeatedField::<i32>::new();
numbers.push(1, &mut arena);
numbers.push(2, &mut arena);
assert_eq!(&numbers[..], &[1, 2]);

// String from a str
let s = String::from_str("hello", &mut arena);
assert_eq!(s.as_str(), "hello");

Structs§

RepeatedField
Like Vec<T> but arena-allocated and never drops elements. Only suitable for trivial (Copy) types.
String
Arena-allocated UTF-8 string for protobuf string fields.

Type Aliases§

Bytes
Alias for RepeatedField<u8>, used for protobuf bytes fields.