CodeSampleX

Ejemplo

wasm-bindgen-macro 0.2.130

Muestra verificada para cargo wasm-bindgen-macro 0.2.130. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó.

sha256:47e3326aa09e9902bb9d276c564bd89593ea2e7b3de8b9b375d1caab2fe6fd1c

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux · alpine · musl x64 cargo

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:cargo/wasm-bindgen-macro@0.2.130
Paquetes
Creado
2026-11-22T21:44:40Z

Contrato

  1. wasm_bindgen exports standalone functions handling primitives, string slices, byte slices, and Option return values
  2. wasm_bindgen exports C-style enums preserving explicit integer discriminants
  3. wasm_bindgen constructor initializes exported structs with readonly public fields
  4. wasm_bindgen getter and setter attributes read and update encapsulated struct fields
  5. wasm_bindgen methods with js_name attribute mutate and reset struct state

Archivos

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[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 = "rustversion"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"

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

[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"

[[package]]
name = "wasm-bindgen"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
dependencies = [
 "cfg-if",
 "rustversion",
 "wasm-bindgen-macro",
 "wasm-bindgen-shared",
]

[[package]]
name = "wasm-bindgen-macro"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
dependencies = [
 "quote",
 "wasm-bindgen-macro-support",
]

[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
dependencies = [
 "bumpalo",
 "proc-macro2",
 "quote",
 "syn",
 "wasm-bindgen-shared",
]

[[package]]
name = "wasm-bindgen-macro-verify"
version = "0.1.0"
dependencies = [
 "wasm-bindgen",
 "wasm-bindgen-macro",
]

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
dependencies = [
 "unicode-ident",
]
Cargo.toml
[package]
name = "wasm-bindgen-macro-verify"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
wasm-bindgen-macro = "=0.2.130"
wasm-bindgen = "=0.2.130"

[[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/wasm-bindgen-macro@0.2.130
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/wasm-bindgen-macro@0.2.130
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:92e92c433d8630bb2b695ba1b74cbb529b89d430640be38e4be3eb11aca7a0c7","contract":["wasm_bindgen exports standalone functions handling primitives, string slices, byte slices, and Option return values","wasm_bindgen exports C-style enums preserving explicit integer discriminants","wasm_bindgen constructor initializes exported structs with readonly public fields","wasm_bindgen getter and setter attributes read and update encapsulated struct fields","wasm_bindgen methods with js_name attribute mutate and reset struct state"],"goal":"verify pkg:cargo/wasm-bindgen-macro@0.2.130","kind":"HOW","packages":["pkg:cargo/wasm-bindgen-macro@0.2.130"],"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/wasm-bindgen-macro@0.2.130"],"schemaVersion":1,"subject":"pkg:cargo/wasm-bindgen-macro@0.2.130","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/wasm-bindgen-macro@0.2.130",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/wasm-bindgen-macro@0.2.130"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/lib.rs
use wasm_bindgen_macro::wasm_bindgen;

#[wasm_bindgen]
pub fn clamp_i32(value: i32, min: i32, max: i32) -> i32 {
    if value < min {
        min
    } else if value > max {
        max
    } else {
        value
    }
}

#[wasm_bindgen]
pub fn join_label(prefix: &str, suffix: &str) -> String {
    format!("{}:{}", prefix, suffix)
}

#[wasm_bindgen]
pub fn reverse_bytes(input: &[u8]) -> Vec<u8> {
    input.iter().rev().copied().collect()
}

#[wasm_bindgen]
pub fn safe_divide(numerator: i32, denominator: i32) -> Option<i32> {
    if denominator == 0 {
        None
    } else {
        Some(numerator / denominator)
    }
}

#[wasm_bindgen]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum JobState {
    Pending = 0,
    Running = 1,
    Completed = 2,
    Failed = 99,
}

#[wasm_bindgen]
pub struct Accumulator {
    #[wasm_bindgen(readonly)]
    pub id: u32,
    total: i64,
    label: String,
}

#[wasm_bindgen]
impl Accumulator {
    #[wasm_bindgen(constructor)]
    pub fn new(id: u32, label: String) -> Accumulator {
        Accumulator {
            id,
            total: 0,
            label,
        }
    }

    #[wasm_bindgen(getter)]
    pub fn total(&self) -> i64 {
        self.total
    }

    #[wasm_bindgen(getter)]
    pub fn label(&self) -> String {
        self.label.clone()
    }

    #[wasm_bindgen(setter)]
    pub fn set_label(&mut self, next: String) {
        self.label = next;
    }

    #[wasm_bindgen(js_name = addDelta)]
    pub fn add_delta(&mut self, delta: i64) -> i64 {
        self.total += delta;
        self.total
    }

    pub fn reset(&mut self) {
        self.total = 0;
    }
}
test/contract.rs
use wasm_bindgen_macro::wasm_bindgen;
use wasm_bindgen_macro_verify::{
    clamp_i32, join_label, reverse_bytes, safe_divide, Accumulator, JobState,
};

#[wasm_bindgen]
pub fn double_u32(n: u32) -> u32 {
    n * 2
}

fn main() {
    // 1. Standalone exported functions with primitives, string slices, byte slices, and Option
    assert_eq!(double_u32(21), 42);
    assert_eq!(clamp_i32(-5, 0, 10), 0);
    assert_eq!(clamp_i32(7, 0, 10), 7);
    assert_eq!(clamp_i32(99, 0, 10), 10);
    assert_eq!(join_label("env", "prod"), "env:prod");
    assert_eq!(reverse_bytes(&[1, 2, 3, 4]), vec![4, 3, 2, 1]);
    assert_eq!(safe_divide(20, 4), Some(5));
    assert_eq!(safe_divide(20, 0), None);

    // 2. Exported C-style enum preserves explicit discriminants
    assert_eq!(JobState::Pending as i32, 0);
    assert_eq!(JobState::Running as i32, 1);
    assert_eq!(JobState::Completed as i32, 2);
    assert_eq!(JobState::Failed as i32, 99);

    // 3. Exported struct with readonly field and constructor
    let mut acc = Accumulator::new(7, "metrics".to_string());
    assert_eq!(acc.id, 7);
    assert_eq!(acc.total(), 0);
    assert_eq!(acc.label(), "metrics");

    // 4. Getter and setter attributes read and update struct fields
    acc.set_label("summary".to_string());
    assert_eq!(acc.label(), "summary");

    // 5. Exported methods with js_name attribute and state mutation
    assert_eq!(acc.add_delta(12), 12);
    assert_eq!(acc.add_delta(-3), 9);
    assert_eq!(acc.total(), 9);
    acc.reset();
    assert_eq!(acc.total(), 0);
}

Seeder de origen

anónimo