CodeSampleX

示例

backtrace 0.3.76: backtrace::trace

已验证示例 — cargo backtrace 0.3.76: backtrace::trace. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: backtrace::trace yields stack frames to the provided…

sha256:4938492fa86d9b2964736ac78e8884c0ee29aa94eff58343f67c5dd990d7753e

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux · alpine · musl 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-10-09

案例

HOW
目标
verify backtrace::trace in pkg:cargo/backtrace@0.3.76
包
符号
  • backtrace::trace
创建时间
2026-10-09T08:17:02Z

契约

  1. backtrace::trace yields stack frames to the provided closure
  2. backtrace::trace yields frames with valid non-null instruction pointer
  3. backtrace::trace terminates iteration early when closure returns false
  4. backtrace::trace captures deeper stack during nested function calls

文件

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.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 = "addr2line"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b"
dependencies = [
 "gimli",
]

[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"

[[package]]
name = "backtrace"
version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6"
dependencies = [
 "addr2line",
 "cfg-if",
 "libc",
 "miniz_oxide",
 "object",
 "rustc-demangle",
 "windows-link",
]

[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[package]]
name = "gimli"
version = "0.32.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"

[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"

[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"

[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
 "adler2",
]

[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
 "memchr",
]

[[package]]
name = "rustc-demangle"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b74b56ffa8bb2830709a538c2cbcae9aa062db0d2a42563bfb09bdaae44020eb"

[[package]]
name = "sample-backtrace"
version = "1.0.0"
dependencies = [
 "backtrace",
]

[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
Cargo.toml
[package]
name = "sample-backtrace"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
backtrace = "=0.3.76"

[[bin]]
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 backtrace::trace in pkg:cargo/backtrace@0.3.76
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/backtrace@0.3.76
Demonstrate these symbols/APIs:
  - backtrace::trace

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:04f3a9f5c6db4c12db902c67cf54b4c166aaacbc8324bc11bcf28d4aaa9b2630","contract":["backtrace::trace yields stack frames to the provided closure","backtrace::trace yields frames with valid non-null instruction pointer","backtrace::trace terminates iteration early when closure returns false","backtrace::trace captures deeper stack during nested function calls"],"goal":"verify backtrace::trace in pkg:cargo/backtrace@0.3.76","kind":"HOW","packages":["pkg:cargo/backtrace@0.3.76"],"schemaVersion":1,"symbols":["backtrace::trace"]},"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/backtrace@0.3.76"],"schemaVersion":1,"subject":"pkg:cargo/backtrace@0.3.76","symbols":["backtrace::trace"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify backtrace::trace in pkg:cargo/backtrace@0.3.76",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/backtrace@0.3.76"
  ],
  "symbols": [
    "backtrace::trace"
  ]
}
src/lib.rs
//! Clean-room verification sample for backtrace.

pub use backtrace::*;
test/contract.rs
use backtrace::trace;

fn nested_call(target_depth: usize, current_depth: usize, ips: &mut Vec<*mut core::ffi::c_void>) {
    if current_depth < target_depth {
        nested_call(target_depth, current_depth + 1, ips);
    } else {
        trace(|frame| {
            ips.push(frame.ip());
            true
        });
    }
}

fn main() {
    // 1. backtrace::trace yields stack frames to the provided closure
    let mut frames = Vec::new();
    trace(|frame| {
        frames.push(frame.ip());
        true
    });
    assert!(!frames.is_empty(), "Expected at least one frame from trace");

    // 2. backtrace::trace yields frames with valid non-null instruction pointer
    assert!(
        frames.iter().any(|&ip| !ip.is_null()),
        "At least one stack frame should have a non-null instruction pointer"
    );

    // 3. backtrace::trace terminates iteration early when closure returns false
    let mut early_stop_count = 0;
    trace(|_frame| {
        early_stop_count += 1;
        false
    });
    assert_eq!(
        early_stop_count, 1,
        "Trace should have stopped after exactly one frame when closure returns false"
    );

    // 4. backtrace::trace captures deeper stack during nested function calls
    let mut nested_ips = Vec::new();
    nested_call(5, 0, &mut nested_ips);
    assert!(
        nested_ips.len() >= 5,
        "Nested call stack should capture multiple frames (got {})",
        nested_ips.len()
    );

    println!("All backtrace::trace contract assertions passed successfully.");
}

原始种子者

匿名