CodeSampleX

示例

synstructure 0.14.0

已验证示例 — cargo synstructure 0.14.0. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: Structure::new creates a structure AST from DeriveInput for structs…

sha256:af3949adf7667fcc53c703bed8eb988b5276a050e78e2c01946afa692ac46e49

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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-09-21

案例

HOW
目标
verify pkg:cargo/synstructure@0.14.0
包
创建时间
2026-09-21T05:56:09Z

契约

  1. Structure::new creates a structure AST from DeriveInput for structs and enums
  2. Structure::each iterates over fields and generates pattern matching arm expressions
  3. Structure::fold aggregates field expressions across variants with initial values
  4. Structure::filter omits designated fields from match arm patterns
  5. Structure::gen_impl generates trait implementation blocks with derived bounds

文件

  • 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 = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "sample-synstructure"
version = "1.0.0"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
 "synstructure",
]

[[package]]
name = "syn"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "synstructure"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "unicode-ident"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
Cargo.toml
[package]
name = "sample-synstructure"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
synstructure = "=0.14.0"
syn = { version = "=3.0.6", features = ["derive", "parsing", "printing", "clone-impls", "extra-traits"] }
quote = "=1.0.47"
proc-macro2 = "=1.0.107"

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

Use EXACTLY these public packages and versions:
  - pkg:cargo/synstructure@0.14.0

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:8106a8bd857fae4833482573989e79789777ac7cf34ec2061c38cee682aec26b","contract":["Structure::new creates a structure AST from DeriveInput for structs and enums","Structure::each iterates over fields and generates pattern matching arm expressions","Structure::fold aggregates field expressions across variants with initial values","Structure::filter omits designated fields from match arm patterns","Structure::gen_impl generates trait implementation blocks with derived bounds"],"goal":"verify pkg:cargo/synstructure@0.14.0","kind":"HOW","packages":["pkg:cargo/synstructure@0.14.0"],"schemaVersion":1},"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/synstructure@0.14.0"],"schemaVersion":1,"subject":"pkg:cargo/synstructure@0.14.0","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/synstructure@0.14.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/synstructure@0.14.0"
  ]
}
src/lib.rs
//! Clean-room verification sample for synstructure.

pub use synstructure::*;
test/contract.rs
use synstructure::Structure;
use quote::quote;

fn main() {
    // 1. Structure::new creates a structure AST from DeriveInput for structs and enums
    let di_struct: syn::DeriveInput = syn::parse_quote! {
        struct Point {
            x: i32,
            y: i32,
        }
    };
    let s_struct = Structure::new(&di_struct);
    assert_eq!(s_struct.variants().len(), 1);
    assert_eq!(s_struct.variants()[0].bindings().len(), 2);
    assert_eq!(s_struct.variants()[0].bindings()[0].ast().ident.as_ref().unwrap(), "x");
    assert_eq!(s_struct.variants()[0].bindings()[1].ast().ident.as_ref().unwrap(), "y");

    let di_enum: syn::DeriveInput = syn::parse_quote! {
        enum Choice {
            First(i32),
            Second(String, bool),
            Empty,
        }
    };
    let s_enum = Structure::new(&di_enum);
    assert_eq!(s_enum.variants().len(), 3);
    assert_eq!(s_enum.variants()[0].ast().ident, "First");
    assert_eq!(s_enum.variants()[0].bindings().len(), 1);
    assert_eq!(s_enum.variants()[1].ast().ident, "Second");
    assert_eq!(s_enum.variants()[1].bindings().len(), 2);
    assert_eq!(s_enum.variants()[2].ast().ident, "Empty");
    assert_eq!(s_enum.variants()[2].bindings().len(), 0);

    // 2. Structure::each iterates over fields and generates pattern matching arm expressions
    let each_tokens = s_struct.each(|bi| {
        quote!(check(#bi);)
    });
    let each_str = each_tokens.to_string();
    assert!(each_str.contains("Point"));
    assert!(each_str.contains("ref __binding_0"));
    assert!(each_str.contains("ref __binding_1"));
    assert!(each_str.contains("check (__binding_0) ;"));
    assert!(each_str.contains("check (__binding_1) ;"));

    // 3. Structure::fold aggregates field expressions across variants with initial values
    let fold_tokens = s_struct.fold(quote!(0), |acc, bi| {
        quote!(#acc + size_of_val(#bi))
    });
    let fold_str = fold_tokens.to_string();
    assert!(fold_str.contains("0 + size_of_val (__binding_0) + size_of_val (__binding_1)"));

    // 4. Structure::filter omits designated fields from match arm patterns
    let mut s_filtered = Structure::new(&di_struct);
    s_filtered.filter(|bi| {
        bi.ast().ident.as_ref().map_or(false, |ident| ident == "x")
    });
    assert!(s_filtered.variants()[0].omitted_bindings());
    assert_eq!(s_filtered.variants()[0].bindings().len(), 1);
    let pat_str = s_filtered.variants()[0].pat().to_string();
    assert!(pat_str.contains("x : ref __binding_0"));
    assert!(pat_str.contains(".."));
    assert!(!pat_str.contains("y :"));

    // 5. Structure::gen_impl generates trait implementation blocks with derived bounds
    let di_generic: syn::DeriveInput = syn::parse_quote! {
        struct Container<T> {
            item: T,
        }
    };
    let s_generic = Structure::new(&di_generic);
    let impl_tokens = s_generic.gen_impl(quote! {
        gen impl custom_crate::CustomTrait for @Self {
            fn custom_fn(&self) {}
        }
    });
    let impl_str = impl_tokens.to_string();
    assert!(impl_str.contains("custom_crate :: CustomTrait for Container < T >"));
    assert!(impl_str.contains("where T : custom_crate :: CustomTrait"));
    assert!(impl_str.contains("fn custom_fn (& self) { }"));

    println!("All synstructure contract assertions passed successfully.");
}

原始种子者

匿名