示例
synstructure 0.14.0: synstructure
已验证示例 — cargo synstructure 0.14.0: synstructure. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: synstructure Structure creates structural…
sha256:19d5be0c39c25ee222a5373c5722af6685c6f02d2e46465e2563c9eec9fa0f64
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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 synstructure in pkg:cargo/synstructure@0.14.0
- 符号
-
- synstructure
- 创建时间
- 2026-09-21T07:21:24Z
契约
- synstructure Structure creates structural representations of structs and enums from syn DeriveInput
- synstructure each generates pattern match arms executing expressions for each field binding
- synstructure fold aggregates field bindings within each variant into a combined expression
- synstructure bind_with customizes pattern destructuring binding style between Ref and Move
- synstructure filter selectively includes or excludes field bindings based on predicate
- synstructure gen_impl generates trait implementation blocks parameterized over the self type
文件
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
源代码
# 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"
[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"
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 synstructure in pkg:cargo/synstructure@0.14.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/synstructure@0.14.0
Demonstrate these symbols/APIs:
- synstructure
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.
{"case":{"caseId":"case:sha256:679a3d7b7380232bc09287652593261d1d59b401496ee69139acd5b6b6852940","contract":["synstructure Structure creates structural representations of structs and enums from syn DeriveInput","synstructure each generates pattern match arms executing expressions for each field binding","synstructure fold aggregates field bindings within each variant into a combined expression","synstructure bind_with customizes pattern destructuring binding style between Ref and Move","synstructure filter selectively includes or excludes field bindings based on predicate","synstructure gen_impl generates trait implementation blocks parameterized over the self type"],"goal":"verify synstructure in pkg:cargo/synstructure@0.14.0","kind":"HOW","packages":["pkg:cargo/synstructure@0.14.0"],"schemaVersion":1,"symbols":["synstructure"]},"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","symbols":["synstructure"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify synstructure in pkg:cargo/synstructure@0.14.0",
"kind": "HOW",
"packages": [
"pkg:cargo/synstructure@0.14.0"
],
"symbols": [
"synstructure"
]
}
//! Clean-room verification sample for synstructure.
pub use synstructure::*;
use quote::quote;
use synstructure::{BindStyle, Structure};
fn main() {
// 1. synstructure Structure creates structural representations of structs and enums from syn DeriveInput
let enum_ast: syn::DeriveInput = syn::parse_str(
"enum Animal { Dog(String, u32), Cat { name: String, lives: u8 }, Fish }"
).expect("failed to parse enum AST");
let s_enum = Structure::new(&enum_ast);
assert_eq!(s_enum.variants().len(), 3);
assert_eq!(s_enum.variants()[0].ast().ident.to_string(), "Dog");
assert_eq!(s_enum.variants()[0].bindings().len(), 2);
assert_eq!(s_enum.variants()[1].ast().ident.to_string(), "Cat");
assert_eq!(s_enum.variants()[1].bindings().len(), 2);
assert_eq!(s_enum.variants()[2].ast().ident.to_string(), "Fish");
assert_eq!(s_enum.variants()[2].bindings().len(), 0);
let struct_ast: syn::DeriveInput = syn::parse_str(
"struct Point { x: f64, y: f64 }"
).expect("failed to parse struct AST");
let s_struct = Structure::new(&struct_ast);
assert_eq!(s_struct.variants().len(), 1);
assert_eq!(s_struct.variants()[0].bindings().len(), 2);
// 2. synstructure each generates pattern match arms executing expressions for each field binding
let s_each = s_enum.clone();
let each_tokens = s_each.each(|bi| {
quote! {
visited(#bi);
}
});
let each_str = each_tokens.to_string();
assert!(each_str.contains("Animal :: Dog (ref __binding_0 , ref __binding_1 ,) =>"));
assert!(each_str.contains("Animal :: Cat { name : ref __binding_0 , lives : ref __binding_1 , } =>"));
assert!(each_str.contains("Animal :: Fish => { }"));
assert!(each_str.contains("visited (__binding_0) ;"));
assert!(each_str.contains("visited (__binding_1) ;"));
// 3. synstructure fold aggregates field bindings within each variant into a combined expression
let s_fold = s_enum.clone();
let fold_tokens = s_fold.fold(quote!(0usize), |acc, bi| {
quote!(#acc + #bi.size())
});
let fold_str = fold_tokens.to_string();
assert!(fold_str.contains("0usize + __binding_0 . size () + __binding_1 . size ()"));
// 4. synstructure bind_with customizes pattern destructuring binding style between Ref and Move
let mut s_move = s_enum.clone();
s_move.bind_with(|_| BindStyle::Move);
let move_tokens = s_move.each(|bi| quote! { drop(#bi); });
let move_str = move_tokens.to_string();
assert!(move_str.contains("Animal :: Dog (__binding_0 , __binding_1 ,) =>"));
assert!(!move_str.contains("ref __binding_0"));
// 5. synstructure filter selectively includes or excludes field bindings based on predicate
let mut s_filter = s_enum.clone();
s_filter.filter(|bi| {
bi.ast().ident.as_ref().map_or(true, |id| id != "lives")
});
// Cat variant had 2 bindings (name, lives), now lives is filtered out
assert_eq!(s_filter.variants()[1].bindings().len(), 1);
assert_eq!(
s_filter.variants()[1].bindings()[0].ast().ident.as_ref().unwrap().to_string(),
"name"
);
assert!(s_filter.variants()[1].omitted_bindings());
// 6. synstructure gen_impl generates trait implementation blocks parameterized over the self type
let impl_tokens = s_enum.gen_impl(quote! {
gen impl MyTrait for @Self {
fn name(&self) -> &'static str {
"animal"
}
}
});
let impl_str = impl_tokens.to_string();
assert!(impl_str.contains("impl MyTrait for Animal"));
assert!(impl_str.contains("fn name (& self) -> & 'static str"));
println!("All synstructure contract assertions passed successfully.");
}
原始种子者
匿名