CodeSampleX

Beispiel

wasm-bindgen 0.2.130

Verifiziertes Beispiel für cargo wasm-bindgen 0.2.130. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand: #[wasm_bindgen] exports Rust…

sha256:5e6de0a636dacfcba2c7ad48f585c4338000dcc57fe716f246cd55bea585ced2

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux x64 rust cargo

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-22

Fall

HOW
Ziel
verify pkg:cargo/wasm-bindgen@0.2.130
Pakete
Erstellt
2026-11-22T21:36:27Z

Contract

  1. #[wasm_bindgen] exports Rust C-like enums, structs with constructors/methods/getters/setters, and string/byte-slice functions that compile and execute on host targets without invoking imported JS functions
  2. Budget::new(100, Priority::High) initializes limit to 100 and priority to Priority::High; allocate(35) returns true leaving remaining() == 65, allocate(70) returns false, and set_limit(150) updates limit() to 150 and remaining() to 115
  3. format_label("item", 7) returns "item-7" and checksum_bytes(&[10, 20, 30]) returns 60
  4. JsValue::NULL, JsValue::UNDEFINED, JsValue::null(), JsValue::undefined(), and JsValue::from_bool(true/false) construct and drop singleton handles on non-wasm host targets without calling imported JS functions, while JsValue::is_null() panics with "cannot call wasm-bindgen imported functions on non-wasm targets"
  5. UnwrapThrowExt::unwrap_throw unwraps Ok(256) to 256 and expect_throw unwraps Some("ready") to "ready" on host targets

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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-contract"
version = "0.1.0"
dependencies = [
 "wasm-bindgen",
]

[[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-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-contract"
version = "0.1.0"
edition = "2021"

[dependencies]
wasm-bindgen = "=0.2.130"
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@0.2.130
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/wasm-bindgen@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:894b08c95f5fa742c2f63de154b69e1ceedd0ddfe2b72246bcaf9761e64d8f7f","contract":["#[wasm_bindgen] exports Rust C-like enums, structs with constructors/methods/getters/setters, and string/byte-slice functions that compile and execute on host targets without invoking imported JS functions","Budget::new(100, Priority::High) initializes limit to 100 and priority to Priority::High; allocate(35) returns true leaving remaining() == 65, allocate(70) returns false, and set_limit(150) updates limit() to 150 and remaining() to 115","format_label(\"item\", 7) returns \"item-7\" and checksum_bytes(\u0026[10, 20, 30]) returns 60","JsValue::NULL, JsValue::UNDEFINED, JsValue::null(), JsValue::undefined(), and JsValue::from_bool(true/false) construct and drop singleton handles on non-wasm host targets without calling imported JS functions, while JsValue::is_null() panics with \"cannot call wasm-bindgen imported functions on non-wasm targets\"","UnwrapThrowExt::unwrap_throw unwraps Ok(256) to 256 and expect_throw unwraps Some(\"ready\") to \"ready\" on host targets"],"goal":"verify pkg:cargo/wasm-bindgen@0.2.130","kind":"HOW","packages":["pkg:cargo/wasm-bindgen@0.2.130"],"schemaVersion":1,"symbols":["wasm_bindgen::prelude::wasm_bindgen","wasm_bindgen::JsValue","wasm_bindgen::UnwrapThrowExt"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","language":"rust","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/wasm-bindgen@0.2.130"],"schemaVersion":1,"subject":"pkg:cargo/wasm-bindgen@0.2.130","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/wasm-bindgen@0.2.130",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/wasm-bindgen@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::prelude::*;

#[wasm_bindgen]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Priority {
    Low = 1,
    High = 2,
}

#[wasm_bindgen]
pub struct Budget {
    limit: u32,
    spent: u32,
    priority: Priority,
}

#[wasm_bindgen]
impl Budget {
    #[wasm_bindgen(constructor)]
    pub fn new(limit: u32, priority: Priority) -> Self {
        Self {
            limit,
            spent: 0,
            priority,
        }
    }

    pub fn allocate(&mut self, amount: u32) -> bool {
        if self.spent.saturating_add(amount) <= self.limit {
            self.spent += amount;
            true
        } else {
            false
        }
    }

    pub fn remaining(&self) -> u32 {
        self.limit.saturating_sub(self.spent)
    }

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

    #[wasm_bindgen(setter)]
    pub fn set_limit(&mut self, limit: u32) {
        self.limit = limit;
    }

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

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

#[wasm_bindgen]
pub fn checksum_bytes(data: &[u8]) -> u32 {
    data.iter().fold(0u32, |acc, &b| acc.wrapping_add(u32::from(b)))
}
tests/contract.rs
use wasm_bindgen::{JsValue, UnwrapThrowExt};
use wasm_bindgen_contract::{checksum_bytes, format_label, Budget, Priority};

#[test]
fn exported_types_and_functions_work_on_host() {
    let mut budget = Budget::new(100, Priority::High);
    assert_eq!(budget.limit(), 100);
    assert_eq!(budget.priority(), Priority::High);
    assert_eq!(budget.remaining(), 100);

    assert!(budget.allocate(35));
    assert_eq!(budget.remaining(), 65);
    assert!(!budget.allocate(70));
    assert_eq!(budget.remaining(), 65);

    budget.set_limit(150);
    assert_eq!(budget.limit(), 150);
    assert_eq!(budget.remaining(), 115);

    assert_eq!(format_label("item", 7), "item-7");
    assert_eq!(checksum_bytes(&[10, 20, 30]), 60);
}

#[test]
fn host_safe_jsvalue_and_unwrap_throw_work() {
    let _null_const = JsValue::NULL;
    let _undef_const = JsValue::UNDEFINED;
    let _null_fn = JsValue::null();
    let _undef_fn = JsValue::undefined();
    let _bool_true = JsValue::from_bool(true);
    let _bool_false = JsValue::from_bool(false);

    let ok: Result<u32, &str> = Ok(256);
    assert_eq!(ok.unwrap_throw(), 256);

    let some: Option<&str> = Some("ready");
    assert_eq!(some.expect_throw("expected value"), "ready");
}

#[test]
#[should_panic(expected = "cannot call wasm-bindgen imported functions on non-wasm targets")]
fn jsvalue_imported_check_panics_on_non_wasm_host() {
    let _ = JsValue::NULL.is_null();
}

Ursprungs-Seeder

anonym