CodeSampleX

Sample

once_cell_polyfill 1.70.2

Verified sample for cargo once_cell_polyfill 1.70.2. The contract ran on rust 1 · linux alpine/x64 · docker and passed: OnceLock::new creates an empty…

sha256:bc79d8900cdf2e7f659e122f39640c35a168a5e9d4c09883f0a953aeb228a7bf

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
1
Declared environment linux · alpine · musl x64 cargo

Verification-run environments

Environment Contract Stages Run
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-10-11
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-10-11

Case

HOW
Goal
verify pkg:cargo/once_cell_polyfill@1.70.2
Packages
Created
2026-10-11T15:40:00Z

Contract

  1. OnceLock::new creates an empty uninitialized cell and get returns None
  2. OnceLock::set sets the value and returns Ok, but returns Err on subsequent sets
  3. OnceLock::get_or_init computes and caches the value on first call
  4. OnceLock::get_mut and take allow mutating or extracting the value from an unshared cell
  5. OnceLock::into_inner consumes the cell and returns the contained value
  6. OnceLock implements From, Default, Clone, and PartialEq
  7. OnceLock safely coordinates concurrent initialization across threads

Files

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

Download the source artifact (tar.gz)

Source

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"

[[package]]
name = "sample-once-cell-polyfill"
version = "1.0.0"
dependencies = [
 "once_cell_polyfill",
]
Cargo.toml
[package]
name = "sample-once-cell-polyfill"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
once_cell_polyfill = "=1.70.2"

[[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/once_cell_polyfill@1.70.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/once_cell_polyfill@1.70.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:cfd7d6f03993bbc7b7c8f737fec03dde014089015ba9aad4db0f3629c4852f5f","contract":["OnceLock::new creates an empty uninitialized cell and get returns None","OnceLock::set sets the value and returns Ok, but returns Err on subsequent sets","OnceLock::get_or_init computes and caches the value on first call","OnceLock::get_mut and take allow mutating or extracting the value from an unshared cell","OnceLock::into_inner consumes the cell and returns the contained value","OnceLock implements From, Default, Clone, and PartialEq","OnceLock safely coordinates concurrent initialization across threads"],"goal":"verify pkg:cargo/once_cell_polyfill@1.70.2","kind":"HOW","packages":["pkg:cargo/once_cell_polyfill@1.70.2"],"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/once_cell_polyfill@1.70.2"],"schemaVersion":1,"subject":"pkg:cargo/once_cell_polyfill@1.70.2","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/once_cell_polyfill@1.70.2",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/once_cell_polyfill@1.70.2"
  ]
}
src/lib.rs
//! Clean-room verification sample for once_cell_polyfill.

pub use once_cell_polyfill::*;
test/contract.rs
use once_cell_polyfill::sync::OnceLock;
use std::sync::Arc;
use std::thread;

fn main() {
    // 1. OnceLock::new creates an empty uninitialized cell and get returns None
    let cell: OnceLock<u32> = OnceLock::new();
    assert!(cell.get().is_none());

    // 2. OnceLock::set sets the value and returns Ok, but returns Err on subsequent sets
    let cell: OnceLock<u32> = OnceLock::new();
    assert_eq!(cell.set(42), Ok(()));
    assert_eq!(cell.get(), Some(&42));
    assert_eq!(cell.set(99), Err(99));
    assert_eq!(cell.get(), Some(&42));

    // 3. OnceLock::get_or_init computes and caches the value on first call
    let cell: OnceLock<String> = OnceLock::new();
    let mut init_count = 0;
    let val1 = cell.get_or_init(|| {
        init_count += 1;
        "computed".to_string()
    });
    assert_eq!(val1, "computed");
    assert_eq!(init_count, 1);
    let val2 = cell.get_or_init(|| {
        init_count += 1;
        "other".to_string()
    });
    assert_eq!(val2, "computed");
    assert_eq!(init_count, 1);

    // 4. OnceLock::get_mut and take allow mutating or extracting the value from an unshared cell
    let mut cell: OnceLock<i32> = OnceLock::new();
    cell.set(10).unwrap();
    if let Some(val) = cell.get_mut() {
        *val += 5;
    }
    assert_eq!(cell.get(), Some(&15));
    let taken = cell.take();
    assert_eq!(taken, Some(15));
    assert!(cell.get().is_none());

    // 5. OnceLock::into_inner consumes the cell and returns the contained value
    let cell: OnceLock<String> = OnceLock::new();
    cell.set("hello".to_string()).unwrap();
    assert_eq!(cell.into_inner(), Some("hello".to_string()));
    let empty: OnceLock<i32> = OnceLock::new();
    assert_eq!(empty.into_inner(), None);

    // 6. OnceLock implements From, Default, Clone, and PartialEq
    let from_cell: OnceLock<i32> = OnceLock::from(100);
    assert_eq!(from_cell.get(), Some(&100));

    let default_cell: OnceLock<i32> = OnceLock::default();
    assert!(default_cell.get().is_none());

    let cloned = from_cell.clone();
    assert_eq!(cloned.get(), Some(&100));
    assert_eq!(from_cell, cloned);

    // 7. OnceLock safely coordinates concurrent initialization across threads
    let thread_cell = Arc::new(OnceLock::new());
    let mut handles = Vec::new();
    for _ in 0..10 {
        let cell_clone = Arc::clone(&thread_cell);
        handles.push(thread::spawn(move || {
            *cell_clone.get_or_init(|| 42)
        }));
    }
    for h in handles {
        let res = h.join().unwrap();
        assert_eq!(res, 42);
    }
    assert_eq!(thread_cell.get(), Some(&42));

    println!("All once_cell_polyfill contract assertions passed successfully.");
}

Origin Seeder

anonymous