CodeSampleX

サンプル

bumpalo 3.20.4: Bump::new

検証済みサンプル — cargo bumpalo 3.20.4: Bump::new. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: Bump::new() returns a Bump<1> arena with min_align()…

sha256:8e867af29e60aac782dd91482fcea1a8097e1c7e9de2340bd37f250d4ade186d

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux x64 rust 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 Bump::new in pkg:cargo/bumpalo@3.20.4
パッケージ
シンボル
  • Bump::new
作成日
2026-11-23T16:28:29Z

コントラクト

  1. Bump::new() returns a Bump<1> arena with min_align() == 1, allocated_bytes() == 0, allocated_bytes_including_metadata() == 0, chunk_capacity() == 0, and allocation_limit() == None
  2. Allocating a zero-sized value on a freshly constructed Bump::new() succeeds without allocating a backing chunk (allocated_bytes() == 0 and chunk_capacity() == 0)
  3. Allocating values via alloc, alloc_str, and alloc_slice_copy on a Bump::new() arena lazily allocates a backing chunk, preserves and allows mutating values, and satisfies type alignment up to 16 bytes
  4. Calling reset() on a mutable Bump::new() arena reclaims the chunk for reuse with iter_allocated_chunks().count() == 1 after a subsequent allocation
  5. Setting set_allocation_limit(Some(0)) on a fresh Bump::new() arena causes try_alloc to return Err(AllocErr), and clearing the limit with set_allocation_limit(None) allows try_alloc to succeed

ファイル

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs
  • test/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 = "bumpalo-new-sample"
version = "0.1.0"
dependencies = [
 "bumpalo",
]
Cargo.toml
[package]
name = "bumpalo-new-sample"
version = "0.1.0"
edition = "2021"

[dependencies]
bumpalo = "=3.20.4"

[[test]]
name = "contract"
path = "test/contract.rs"
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::new 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::new

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:fb849712c4f1c7d3a459bd456a80a0a8d0ead1bc1e5fadc55c5605d17d119551","contract":["Bump::new() returns a Bump\u003c1\u003e arena with min_align() == 1, allocated_bytes() == 0, allocated_bytes_including_metadata() == 0, chunk_capacity() == 0, and allocation_limit() == None","Allocating a zero-sized value on a freshly constructed Bump::new() succeeds without allocating a backing chunk (allocated_bytes() == 0 and chunk_capacity() == 0)","Allocating values via alloc, alloc_str, and alloc_slice_copy on a Bump::new() arena lazily allocates a backing chunk, preserves and allows mutating values, and satisfies type alignment up to 16 bytes","Calling reset() on a mutable Bump::new() arena reclaims the chunk for reuse with iter_allocated_chunks().count() == 1 after a subsequent allocation","Setting set_allocation_limit(Some(0)) on a fresh Bump::new() arena causes try_alloc to return Err(AllocErr), and clearing the limit with set_allocation_limit(None) allows try_alloc to succeed"],"goal":"verify Bump::new in pkg:cargo/bumpalo@3.20.4","kind":"HOW","packages":["pkg:cargo/bumpalo@3.20.4"],"schemaVersion":1,"symbols":["Bump::new"]},"contractCommand":["cargo","test","--offline","--test","contract"],"environment":{"arch":"x64","compiler":"rustc","ecosystem":"cargo","language":"rust","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::new"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Bump::new in pkg:cargo/bumpalo@3.20.4",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/bumpalo@3.20.4"
  ],
  "symbols": [
    "Bump::new"
  ]
}
src/main.rs
use bumpalo::Bump;

fn main() {
    let mut bump = Bump::new();
    let count = bump.alloc(42_u64);
    let label = bump.alloc_str("bump-allocated");
    println!("{label}={count} allocated_bytes={}", bump.allocated_bytes());
    bump.reset();
}
test/contract.rs
use bumpalo::Bump;

#[repr(align(16))]
struct Aligned16(u64);

#[test]
fn bump_new_starts_empty_with_default_min_align_and_no_limit() {
    let bump: Bump<1> = Bump::new();
    assert_eq!(bump.min_align(), 1);
    assert_eq!(bump.allocated_bytes(), 0);
    assert_eq!(bump.allocated_bytes_including_metadata(), 0);
    assert_eq!(bump.chunk_capacity(), 0);
    assert_eq!(bump.allocation_limit(), None);
}

#[test]
fn bump_new_zst_allocation_does_not_allocate_chunk() {
    let bump = Bump::new();
    let unit = bump.alloc(());
    assert_eq!(*unit, ());
    assert_eq!(bump.allocated_bytes(), 0);
    assert_eq!(bump.chunk_capacity(), 0);
}

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

    let num = bump.alloc(1234_u64);
    assert_eq!(*num, 1234);
    *num += 6;
    assert_eq!(*num, 1240);
    assert_eq!((num as *const u64 as usize) % std::mem::align_of::<u64>(), 0);

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

    let slice = bump.alloc_slice_copy(&[1_u32, 2, 3, 4]);
    slice[0] = 10;
    assert_eq!(slice, &[10, 2, 3, 4]);

    let aligned = bump.alloc(Aligned16(99));
    assert_eq!(aligned.0, 99);
    assert_eq!((aligned as *const Aligned16 as usize) % 16, 0);

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

#[test]
fn bump_new_supports_reset_and_reuse() {
    let mut bump = Bump::new();
    {
        let first = bump.alloc_slice_copy(&[1_u8; 64]);
        assert_eq!(first.len(), 64);
        assert!(bump.allocated_bytes() > 0);
    }

    bump.reset();

    let reused = bump.alloc(77_u32);
    assert_eq!(*reused, 77);
    assert_eq!(bump.iter_allocated_chunks().count(), 1);
}

#[test]
fn bump_new_enforces_allocation_limit_before_first_chunk() {
    let bump = Bump::new();
    bump.set_allocation_limit(Some(0));
    assert_eq!(bump.allocation_limit(), Some(0));
    assert!(bump.try_alloc(5_u32).is_err());

    bump.set_allocation_limit(None);
    assert_eq!(bump.allocation_limit(), None);
    let ok = bump.try_alloc(5_u32).expect("allocation should succeed once limit is cleared");
    assert_eq!(*ok, 5);
}

オリジンシーダー

匿名