CodeSampleX

サンプル

wasm-bindgen 0.2.130: wasm_bindgen

検証済みサンプル — cargo wasm-bindgen 0.2.130: wasm_bindgen. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: #[wasm_bindgen] exports standalone functions…

sha256:03497019d67ebd3cbe2f75c2868fd8f26862282cfa59ca0ec7428c8f0aeb4b09

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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-11-23

ケース

HOW
ゴール
verify wasm_bindgen in pkg:cargo/wasm-bindgen@0.2.130
パッケージ
シンボル
  • wasm_bindgen
作成日
2026-11-23T15:31:51Z

コントラクト

  1. #[wasm_bindgen] exports standalone functions with primitive arguments, Result<T, String> return values, and boolean predicates
  2. #[wasm_bindgen] exports C-like enums with explicit discriminants usable as function parameters and return values
  3. #[wasm_bindgen] exports structs with readonly fields, #[wasm_bindgen(constructor)], #[wasm_bindgen(getter)]/#[wasm_bindgen(setter)], and #[wasm_bindgen(js_name = ...)] methods
  4. #[wasm_bindgen] exports functions accepting &str and &[u8] and returning owned String and Vec<u8>

ファイル

  • 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 = "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-shared"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "wasm-bindgen-verify"
version = "0.1.0"
dependencies = [
 "wasm-bindgen",
]
Cargo.toml
[package]
name = "wasm-bindgen-verify"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
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 wasm_bindgen in pkg:cargo/wasm-bindgen@0.2.130
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/wasm-bindgen@0.2.130
Demonstrate these symbols/APIs:
  - wasm_bindgen
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:18a94bc3af25bdcea9e8ab7020c82f8c677de02face3b53fdbfc87c3ed4c5fac","contract":["#[wasm_bindgen] exports standalone functions with primitive arguments, Result\u003cT, String\u003e return values, and boolean predicates","#[wasm_bindgen] exports C-like enums with explicit discriminants usable as function parameters and return values","#[wasm_bindgen] exports structs with readonly fields, #[wasm_bindgen(constructor)], #[wasm_bindgen(getter)]/#[wasm_bindgen(setter)], and #[wasm_bindgen(js_name = ...)] methods","#[wasm_bindgen] exports functions accepting \u0026str and \u0026[u8] and returning owned String and Vec\u003cu8\u003e"],"goal":"verify wasm_bindgen in pkg:cargo/wasm-bindgen@0.2.130","kind":"HOW","packages":["pkg:cargo/wasm-bindgen@0.2.130"],"schemaVersion":1,"symbols":["wasm_bindgen"]},"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@0.2.130"],"schemaVersion":1,"subject":"pkg:cargo/wasm-bindgen@0.2.130","symbols":["wasm_bindgen"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify wasm_bindgen in pkg:cargo/wasm-bindgen@0.2.130",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/wasm-bindgen@0.2.130"
  ],
  "symbols": [
    "wasm_bindgen"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/lib.rs
//! Clean-room sample verifying `#[wasm_bindgen]` exports in `wasm-bindgen` 0.2.130.

use wasm_bindgen::prelude::wasm_bindgen;

/// Standalone exported function using primitive integers.
#[wasm_bindgen]
pub fn scale_clamp(value: i32, factor: i32, limit: i32) -> i32 {
    let scaled = value.saturating_mul(factor);
    scaled.clamp(-limit, limit)
}

/// Exported function returning `Result<T, String>` for fallible operations.
#[wasm_bindgen]
pub fn checked_divide(numerator: i32, denominator: i32) -> Result<i32, String> {
    if denominator == 0 {
        Err("division by zero".to_string())
    } else {
        Ok(numerator / denominator)
    }
}

/// Exported C-like enum with explicit integer discriminants.
#[wasm_bindgen]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Severity {
    Low = 1,
    Medium = 2,
    High = 3,
}

/// Exported function accepting and returning a `#[wasm_bindgen]` enum.
#[wasm_bindgen]
pub fn escalate(level: Severity) -> Severity {
    match level {
        Severity::Low => Severity::Medium,
        Severity::Medium => Severity::High,
        Severity::High => Severity::High,
    }
}

/// Exported struct combining a readonly field, private state, constructor,
/// getter/setter pair, and custom `js_name` method.
#[wasm_bindgen]
pub struct Meter {
    #[wasm_bindgen(readonly)]
    pub id: u32,
    total: i32,
    step: i32,
}

#[wasm_bindgen]
impl Meter {
    #[wasm_bindgen(constructor)]
    pub fn new(id: u32, initial: i32) -> Meter {
        Meter {
            id,
            total: initial,
            step: 1,
        }
    }

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

    #[wasm_bindgen(setter)]
    pub fn set_step(&mut self, step: i32) {
        self.step = step;
    }

    pub fn advance(&mut self) -> i32 {
        self.total += self.step;
        self.total
    }

    #[wasm_bindgen(js_name = resetTotal)]
    pub fn reset_total(&mut self, value: i32) {
        self.total = value;
    }

    pub fn total(&self) -> i32 {
        self.total
    }
}

/// Exported function operating on `&str` and returning an owned `String`.
#[wasm_bindgen]
pub fn normalize_label(input: &str) -> String {
    input.trim().to_ascii_lowercase()
}

/// Exported function operating on `&[u8]` and returning `Vec<u8>`.
#[wasm_bindgen]
pub fn xor_bytes(data: &[u8], mask: u8) -> Vec<u8> {
    data.iter().map(|b| b ^ mask).collect()
}
test/contract.rs
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen_verify::{
    checked_divide, escalate, normalize_label, scale_clamp, xor_bytes, Meter, Severity,
};

#[wasm_bindgen]
pub fn is_non_empty(text: &str) -> bool {
    !text.is_empty()
}

fn main() {
    // 1. Standalone exported functions with primitives and Option/Result
    assert_eq!(scale_clamp(4, 5, 100), 20);
    assert_eq!(scale_clamp(40, 5, 100), 100);
    assert_eq!(scale_clamp(-40, 5, 100), -100);
    assert_eq!(checked_divide(21, 3), Ok(7));
    assert_eq!(checked_divide(21, 0), Err("division by zero".to_string()));
    assert!(is_non_empty("ok"));
    assert!(!is_non_empty(""));

    // 2. Exported C-like enum with explicit discriminants and enum-valued function
    assert_eq!(Severity::Low as u32, 1);
    assert_eq!(Severity::Medium as u32, 2);
    assert_eq!(Severity::High as u32, 3);
    assert_eq!(escalate(Severity::Low), Severity::Medium);
    assert_eq!(escalate(Severity::Medium), Severity::High);
    assert_eq!(escalate(Severity::High), Severity::High);

    // 3. Exported struct with readonly field, constructor, getter/setter, and js_name method
    let mut meter = Meter::new(7, 10);
    assert_eq!(meter.id, 7);
    assert_eq!(meter.total(), 10);
    assert_eq!(meter.step(), 1);
    assert_eq!(meter.advance(), 11);
    meter.set_step(5);
    assert_eq!(meter.step(), 5);
    assert_eq!(meter.advance(), 16);
    meter.reset_total(0);
    assert_eq!(meter.total(), 0);

    // 4. Exported string and byte-slice functions
    assert_eq!(normalize_label("  Wasm-Bindgen  "), "wasm-bindgen");
    let encoded = xor_bytes(&[0x10, 0x20, 0x33], 0xFF);
    assert_eq!(encoded, vec![0xEF, 0xDF, 0xCC]);
    assert_eq!(xor_bytes(&encoded, 0xFF), vec![0x10, 0x20, 0x33]);

    println!("wasm_bindgen 0.2.130 contract passed");
}

オリジンシーダー

匿名