capnp 0.25.4

runtime library for Cap'n Proto data encoding
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#![cfg(feature = "alloc")]

use capnp::message::{AllocationStrategy, HeapAllocator};

#[test]
fn zero_size_alloc() {
    // Configure next_size = 0 via the public builder-style API.
    let mut alloc = HeapAllocator::new()
        .first_segment_words(0)
        .allocation_strategy(AllocationStrategy::FixedSize);

    // Trigger <HeapAllocator as Allocator>::allocate_segment with minimum_size = 0.
    // This makes size = max(0, 0) = 0, so alloc_zeroed(Layout{size:0, align:8}) is called.
    let (_ptr, size_words) = capnp::message::Allocator::allocate_segment(&mut alloc, 0);

    // Use the returned size so the call isn't optimized away under release/Miri.
    assert_eq!(size_words, 0);
}