CodeSampleX

Sample

bumpalo 3.20.4: Bump::alloc_str

Verified sample for cargo bumpalo 3.20.4: Bump::alloc_str. The contract ran on rust 1 · linux alpine/x64 · docker and passed: Bump::alloc_str copies a…

sha256:554569328a613d8fbf6e1000868186caa1644a2f13121803c4e142b3d7beb3b3

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux · alpine · musl x64 cargo

Verification-run environments

Environment Contract Stages Run
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-23

Case

HOW
Goal
verify Bump::alloc_str in pkg:cargo/bumpalo@3.20.4
Packages
Symbols
  • Bump::alloc_str
Created
2026-11-23T16:23:03Z

Contract

  1. Bump::alloc_str copies a non-empty &str into the arena and returns a distinct &mut str with identical content
  2. Bump::alloc_str returns a mutable string slice that supports in-place modification
  3. Bump::alloc_str preserves empty strings and multi-byte UTF-8 text without corruption
  4. Multiple Bump::alloc_str calls coexist independently in the same arena and Bump::reset reclaims arena space for subsequent allocations

Files

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Download the source artifact (tar.gz)

Source

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "bumpalo"
version = "3.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"

[[package]]
name = "sample-bumpalo-alloc-str"
version = "1.0.0"
dependencies = [
 "bumpalo",
]
Cargo.toml
[package]
name = "sample-bumpalo-alloc-str"
version = "1.0.0"
edition = "2021"
publish = false

[[bin]]
name = "contract"
path = "test/contract.rs"

[dependencies]
bumpalo = "=3.20.4"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify Bump::alloc_str in pkg:cargo/bumpalo@3.20.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/bumpalo@3.20.4
Demonstrate these symbols/APIs:
  - Bump::alloc_str

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:615acb25e163b96f1705676ae4a3053d1c0870c89c3f44f723a836fd414aba58","contract":["Bump::alloc_str copies a non-empty \u0026str into the arena and returns a distinct \u0026mut str with identical content","Bump::alloc_str returns a mutable string slice that supports in-place modification","Bump::alloc_str preserves empty strings and multi-byte UTF-8 text without corruption","Multiple Bump::alloc_str calls coexist independently in the same arena and Bump::reset reclaims arena space for subsequent allocations"],"goal":"verify Bump::alloc_str in pkg:cargo/bumpalo@3.20.4","kind":"HOW","packages":["pkg:cargo/bumpalo@3.20.4"],"schemaVersion":1,"symbols":["Bump::alloc_str"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/bumpalo@3.20.4"],"schemaVersion":1,"subject":"pkg:cargo/bumpalo@3.20.4","symbols":["Bump::alloc_str"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Bump::alloc_str in pkg:cargo/bumpalo@3.20.4",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/bumpalo@3.20.4"
  ],
  "symbols": [
    "Bump::alloc_str"
  ]
}
src/lib.rs
//! Clean-room verification sample for Bump::alloc_str in bumpalo 3.20.4.

pub use bumpalo::Bump;

/// Allocates a copy of `input` inside `arena` and converts ASCII characters to uppercase in place.
pub fn alloc_uppercase<'a>(arena: &'a Bump, input: &str) -> &'a mut str {
    let s = arena.alloc_str(input);
    s.make_ascii_uppercase();
    s
}
test/contract.rs
use bumpalo::Bump;

fn main() {
    let mut bump = Bump::new();

    // 1. Bump::alloc_str copies a non-empty &str into the arena and returns a distinct &mut str with identical content
    let source = String::from("hello bumpalo");
    let allocated: &mut str = bump.alloc_str(&source);
    assert_eq!(allocated, "hello bumpalo");
    assert_eq!(allocated.len(), source.len());
    assert_ne!(allocated.as_ptr(), source.as_ptr());

    // 2. Bump::alloc_str returns a mutable string slice that supports in-place modification
    allocated.make_ascii_uppercase();
    assert_eq!(allocated, "HELLO BUMPALO");
    assert_eq!(source, "hello bumpalo");

    // Mutate via helper as well
    let helper_upper = sample_bumpalo_alloc_str::alloc_uppercase(&bump, "arena text");
    assert_eq!(helper_upper, "ARENA TEXT");

    // 3. Bump::alloc_str preserves empty strings and multi-byte UTF-8 text without corruption
    let empty = bump.alloc_str("");
    assert_eq!(empty, "");
    assert_eq!(empty.len(), 0);

    let utf8_src = "héllo 世界 🚀";
    let utf8_alloc = bump.alloc_str(utf8_src);
    assert_eq!(utf8_alloc, utf8_src);
    assert_eq!(utf8_alloc.len(), utf8_src.len());
    assert_eq!(utf8_alloc.chars().count(), utf8_src.chars().count());
    assert_ne!(utf8_alloc.as_ptr(), utf8_src.as_ptr());

    // 4. Multiple Bump::alloc_str calls coexist independently in the same arena and Bump::reset reclaims space
    let first = bump.alloc_str("first");
    let second = bump.alloc_str("second");
    assert_ne!(first.as_ptr(), second.as_ptr());
    first.make_ascii_uppercase();
    assert_eq!(first, "FIRST");
    assert_eq!(second, "second");
    assert!(bump.allocated_bytes() > 0);

    // Ensure earlier allocations are still intact alongside later ones
    assert_eq!(allocated, "HELLO BUMPALO");
    assert_eq!(utf8_alloc, utf8_src);

    // Reset the arena and verify fresh alloc_str allocations work cleanly
    bump.reset();
    let after_reset = bump.alloc_str("reused arena");
    assert_eq!(after_reset, "reused arena");

    println!("All Bump::alloc_str contract assertions passed.");
}

Origin Seeder

anonymous