CodeSampleX

Ejemplo

spin 0.9.9: spin::Lazy

Muestra verificada para cargo spin 0.9.9: spin::Lazy. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó: spin::Lazy::new constructs an…

sha256:969b7f4eea2565a504ea955010286d6a671788a7fb838324d8e8ef082e605581

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 x64 cargo

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
rust 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-04

Caso

HOW
Objetivo
verify spin::Lazy in pkg:cargo/spin@0.9.9
Paquetes
Símbolos
  • spin::Lazy
Creado
2026-11-04T15:27:32Z

Contrato

  1. spin::Lazy::new constructs an uninitialized lazy value without running the initialization closure until first access
  2. Dereferencing spin::Lazy or calling spin::Lazy::force runs the initialization closure once and returns a shared reference to the initialized value
  3. spin::Lazy::default creates a lazy value initialized via Default::default on first access

Archivos

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.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 = "lock_api"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
 "scopeguard",
]

[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"

[[package]]
name = "spin"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e"
dependencies = [
 "lock_api",
]

[[package]]
name = "spin-lazy-sample"
version = "0.1.0"
dependencies = [
 "spin",
]
Cargo.toml
[package]
name = "spin-lazy-sample"
version = "0.1.0"
edition = "2021"

[dependencies]
spin = "=0.9.9"
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 spin::Lazy in pkg:cargo/spin@0.9.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/spin@0.9.9
Demonstrate these symbols/APIs:
  - spin::Lazy

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:7bd8fa419dcef2e651adff92600f397f33ac6a154c5ee79ffd4c17e15c389a84","contract":["spin::Lazy::new constructs an uninitialized lazy value without running the initialization closure until first access","Dereferencing spin::Lazy or calling spin::Lazy::force runs the initialization closure once and returns a shared reference to the initialized value","spin::Lazy::default creates a lazy value initialized via Default::default on first access"],"goal":"verify spin::Lazy in pkg:cargo/spin@0.9.9","kind":"HOW","packages":["pkg:cargo/spin@0.9.9"],"schemaVersion":1,"symbols":["spin::Lazy"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/spin@0.9.9"],"schemaVersion":1,"subject":"pkg:cargo/spin@0.9.9","symbols":["spin::Lazy"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify spin::Lazy in pkg:cargo/spin@0.9.9",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/spin@0.9.9"
  ],
  "symbols": [
    "spin::Lazy"
  ]
}
src/main.rs
use core::sync::atomic::{AtomicUsize, Ordering};
use spin::Lazy;

static INIT_COUNT: AtomicUsize = AtomicUsize::new(0);
static COMPUTED: Lazy<usize> = Lazy::new(|| {
    INIT_COUNT.fetch_add(1, Ordering::SeqCst);
    21 * 2
});

fn main() {
    // Before first access, the initializer closure has not run.
    assert_eq!(INIT_COUNT.load(Ordering::SeqCst), 0);

    // Dereferencing Lazy initializes the value once and returns a shared reference to it.
    assert_eq!(*COMPUTED, 42);
    assert_eq!(INIT_COUNT.load(Ordering::SeqCst), 1);

    // Calling Lazy::force returns a reference to the already-initialized value without re-running the initializer.
    assert_eq!(*Lazy::force(&COMPUTED), 42);
    assert_eq!(INIT_COUNT.load(Ordering::SeqCst), 1);

    // Lazy::default creates a Lazy that initializes with T::default() on first access.
    let default_lazy: Lazy<Vec<i32>> = Lazy::default();
    assert!(default_lazy.is_empty());
}

Seeder de origen

anónimo