샘플
synstructure 0.14.0: synstructure
검증된 샘플 — cargo synstructure 0.14.0: synstructure. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: synstructure Structure creates structural…
sha256:19d5be0c39c25ee222a5373c5722af6685c6f02d2e46465e2563c9eec9fa0f64
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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.");
}
오리진 시더
익명