CodeSampleX

샘플

bumpalo 3.20.4

검증된 샘플 — cargo bumpalo 3.20.4. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Bump::new, Bump::alloc, Bump::alloc_with, Bump::alloc_str…

sha256:4e93ca5ace199e3b5357590366eee61da96840ff4458efb7ffd6c0df948eb4d3

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux x64 cargo

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:cargo/bumpalo@3.20.4
패키지
생성일
2026-11-23T15:39:22Z

컨트랙트

  1. Bump::new, Bump::alloc, Bump::alloc_with, Bump::alloc_str, Bump::alloc_slice_copy, Bump::alloc_slice_clone, Bump::alloc_slice_fill_default, and Bump::alloc_slice_fill_iter allocate mutable arena references and track Bump::allocated_bytes
  2. Bump::with_capacity and Bump::reset reclaim arena space while retaining at least the existing Bump::chunk_capacity for subsequent allocations
  3. Bump::set_allocation_limit on a fresh Bump::new arena (0 allocated bytes) allows small Bump::try_alloc calls within the limit and returns Err(AllocErr) when a new chunk would exceed the limit

파일

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs
  • tests/contract.rs

소스 아티팩트 내려받기 (tar.gz)

소스

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"
version = "0.1.0"
dependencies = [
 "bumpalo",
]
Cargo.toml
[package]
name = "sample-bumpalo"
version = "0.1.0"
edition = "2021"

[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 pkg:cargo/bumpalo@3.20.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/bumpalo@3.20.4
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:bcbc1ebba50286edecb15fc47321f99e1e3143c80ef644b47c1efa59f610c253","contract":["Bump::new, Bump::alloc, Bump::alloc_with, Bump::alloc_str, Bump::alloc_slice_copy, Bump::alloc_slice_clone, Bump::alloc_slice_fill_default, and Bump::alloc_slice_fill_iter allocate mutable arena references and track Bump::allocated_bytes","Bump::with_capacity and Bump::reset reclaim arena space while retaining at least the existing Bump::chunk_capacity for subsequent allocations","Bump::set_allocation_limit on a fresh Bump::new arena (0 allocated bytes) allows small Bump::try_alloc calls within the limit and returns Err(AllocErr) when a new chunk would exceed the limit"],"goal":"verify pkg:cargo/bumpalo@3.20.4","kind":"HOW","packages":["pkg:cargo/bumpalo@3.20.4"],"schemaVersion":1},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","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","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/bumpalo@3.20.4",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/bumpalo@3.20.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/main.rs
use bumpalo::Bump;

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

    let number = bump.alloc(41u32);
    *number += 1;
    assert_eq!(*number, 42);

    let greeting = bump.alloc_str("hello bumpalo");
    assert_eq!(greeting, "hello bumpalo");

    let copied = bump.alloc_slice_copy(&[10u16, 20, 30]);
    copied[1] = 25;
    assert_eq!(copied, &[10, 25, 30]);

    let cloned = bump.alloc_slice_clone(&[String::from("a"), String::from("b")]);
    assert_eq!(cloned, &[String::from("a"), String::from("b")]);

    let from_iter = bump.alloc_slice_fill_iter((0u32..4).map(|n| n * n));
    assert_eq!(from_iter, &[0, 1, 4, 9]);

    let bytes_before_reset = bump.allocated_bytes();
    assert!(bytes_before_reset > 0);

    bump.reset();
    let reused = bump.alloc_with(|| 99u64);
    assert_eq!(*reused, 99);

    println!("CONTRACT_OK");
}
tests/contract.rs
use bumpalo::Bump;

#[test]
fn alloc_values_strings_and_slices_in_arena() {
    let bump = Bump::new();

    let value = bump.alloc(123i64);
    *value += 7;
    assert_eq!(*value, 130);

    let computed = bump.alloc_with(|| (10u32, 20u32));
    assert_eq!(*computed, (10, 20));

    let text = bump.alloc_str("arena-text");
    assert_eq!(text, "arena-text");

    let slice_copy = bump.alloc_slice_copy(&[1u8, 2, 3, 4]);
    slice_copy[0] = 9;
    assert_eq!(slice_copy, &[9, 2, 3, 4]);

    let slice_clone = bump.alloc_slice_clone(&[String::from("x"), String::from("y")]);
    assert_eq!(slice_clone, &[String::from("x"), String::from("y")]);

    let slice_default: &mut [u32] = bump.alloc_slice_fill_default(3);
    assert_eq!(slice_default, &[0, 0, 0]);

    let slice_iter = bump.alloc_slice_fill_iter([2u32, 4, 6]);
    assert_eq!(slice_iter, &[2, 4, 6]);

    assert!(bump.allocated_bytes() > 0);
}

#[test]
fn reset_reuses_arena_memory_without_freeing_current_chunk() {
    let mut bump = Bump::with_capacity(512);
    let _first = bump.alloc_slice_fill_copy(64, 7u8);
    let cap_before = bump.chunk_capacity();
    assert!(cap_before >= 64);

    bump.reset();

    let cap_after = bump.chunk_capacity();
    assert!(cap_after >= cap_before);

    let second = bump.alloc_slice_fill_copy(32, 9u8);
    assert_eq!(second.len(), 32);
    assert!(second.iter().all(|&b| b == 9));
}

#[test]
fn allocation_limit_rejects_oversized_try_alloc() {
    let bump = Bump::new();
    assert_eq!(bump.allocated_bytes(), 0);

    bump.set_allocation_limit(Some(1024));
    assert_eq!(bump.allocation_limit(), Some(1024));

    let ok_val = bump.try_alloc(42u32).expect("small allocation fits within limit");
    assert_eq!(*ok_val, 42);

    let too_big = bump.try_alloc([0u8; 4096]);
    assert!(too_big.is_err(), "allocation exceeding limit must return Err(AllocErr)");
}

오리진 시더

익명