xocomil 0.3.0

A lightweight, zero-allocation HTTP/1.1 request parser and response writer
Documentation
//! Heap-allocation audit for `xocomil::media`.
//!
//! Run with: `cargo test --release --features dhat-heap --test alloc_media`
//!
//! See `alloc_pct.rs` for the design rationale (one test per binary,
//! delta-based assertions).

#![cfg(feature = "dhat-heap")]

use std::hint::black_box;

use xocomil::media::MediaType;

#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

#[test]
fn media_hot_paths_zero_alloc() {
    let _profiler = dhat::Profiler::builder().testing().build();
    let baseline = dhat::HeapStats::get();

    // -- Parse a variety of shapes --------------------------------------
    let inputs: [&[u8]; 4] = [
        b"application/json",
        b"text/html; charset=utf-8",
        b"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
        b"multipart/form-data; boundary=\"----abc; xyz\"",
    ];
    for _ in 0..1000 {
        for input in &inputs {
            let mt = MediaType::parse(black_box(input)).unwrap();
            black_box(mt);
        }
    }

    // -- Parse + param lookup (multipart extractor flow) ----------------
    let multipart = b"multipart/form-data; charset=utf-8; boundary=abc123";
    for _ in 0..1000 {
        let mt = MediaType::parse(black_box(multipart)).unwrap();
        black_box(mt.param("boundary"));
        black_box(mt.param("charset"));
        black_box(mt.param("missing"));
    }

    let stats = dhat::HeapStats::get();
    dhat::assert_eq!(stats.total_blocks - baseline.total_blocks, 0);
    dhat::assert_eq!(stats.total_bytes - baseline.total_bytes, 0);
}