CodeSampleX

Sample

zerovec 0.11.6: zerovec::ule::AsULE

Verified sample for cargo zerovec 0.11.6: zerovec::ule::AsULE. The contract ran on rust 1 · linux alpine/x64 · docker and passed.

sha256:6f7fce7244ddff6e57aff33a5b29821fab1cc7287267606d64f8bbb64e4b0ca3

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
1
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 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-09-21

Case

HOW
Goal
verify zerovec::ule::AsULE in pkg:cargo/zerovec@0.11.6
Packages
Symbols
  • zerovec::ule::AsULE
Created
2026-09-21T08:16:16Z

Contract

  1. AsULE::to_unaligned and AsULE::from_unaligned round-trip primitive integer and boolean types
  2. AsULE converts char to CharULE validating 3-byte little-endian Unicode scalar values
  3. AsULE is implemented for fixed-size arrays and tuples preserving element-wise unaligned conversion
  4. AsULE enables zero-copy representation for Option<T> via OptionULE distinguishing Some and None
  5. Custom types implementing AsULE can be stored and retrieved zero-copy in ZeroVec

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 = "sample-zerovec"
version = "1.0.0"
dependencies = [
 "zerovec",
]

[[package]]
name = "zerofrom"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"

[[package]]
name = "zerovec"
version = "0.11.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239"
dependencies = [
 "zerofrom",
]
Cargo.toml
[package]
name = "sample-zerovec"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
zerovec = "=0.11.6"

[[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 zerovec::ule::AsULE in pkg:cargo/zerovec@0.11.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/zerovec@0.11.6
Demonstrate these symbols/APIs:
  - zerovec::ule::AsULE

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:6c0d0749e9fd0ef0f32b604fcf519527ace9899bbe78335790d7d00ce4841d38","contract":["AsULE::to_unaligned and AsULE::from_unaligned round-trip primitive integer and boolean types","AsULE converts char to CharULE validating 3-byte little-endian Unicode scalar values","AsULE is implemented for fixed-size arrays and tuples preserving element-wise unaligned conversion","AsULE enables zero-copy representation for Option\u003cT\u003e via OptionULE distinguishing Some and None","Custom types implementing AsULE can be stored and retrieved zero-copy in ZeroVec"],"goal":"verify zerovec::ule::AsULE in pkg:cargo/zerovec@0.11.6","kind":"HOW","packages":["pkg:cargo/zerovec@0.11.6"],"schemaVersion":1,"symbols":["zerovec::ule::AsULE"]},"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/zerovec@0.11.6"],"schemaVersion":1,"subject":"pkg:cargo/zerovec@0.11.6","symbols":["zerovec::ule::AsULE"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify zerovec::ule::AsULE in pkg:cargo/zerovec@0.11.6",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/zerovec@0.11.6"
  ],
  "symbols": [
    "zerovec::ule::AsULE"
  ]
}
src/lib.rs
//! Clean-room verification sample for zerovec.

pub use zerovec::*;
test/contract.rs
use zerovec::ule::{AsULE, CharULE, OptionULE, RawBytesULE, ULE, UleError};
use zerovec::ZeroVec;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct Coordinate {
    x: i16,
    y: i16,
}

#[repr(C, packed)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct CoordinateULE {
    x: <i16 as AsULE>::ULE,
    y: <i16 as AsULE>::ULE,
}

// Safety: CoordinateULE is repr(C, packed), aligned to 1, contains only ULE fields,
// has no padding, and validates sub-fields without leftover bytes.
unsafe impl ULE for CoordinateULE {
    fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> {
        let size = core::mem::size_of::<Self>();
        if bytes.len() % size != 0 {
            return Err(UleError::length::<Self>(bytes.len()));
        }
        for chunk in bytes.chunks_exact(size) {
            <<i16 as AsULE>::ULE as ULE>::validate_bytes(&chunk[0..2])?;
            <<i16 as AsULE>::ULE as ULE>::validate_bytes(&chunk[2..4])?;
        }
        Ok(())
    }
}

impl AsULE for Coordinate {
    type ULE = CoordinateULE;

    #[inline]
    fn to_unaligned(self) -> Self::ULE {
        CoordinateULE {
            x: self.x.to_unaligned(),
            y: self.y.to_unaligned(),
        }
    }

    #[inline]
    fn from_unaligned(unaligned: Self::ULE) -> Self {
        Coordinate {
            x: i16::from_unaligned(unaligned.x),
            y: i16::from_unaligned(unaligned.y),
        }
    }
}

fn main() {
    // 1. AsULE::to_unaligned and AsULE::from_unaligned round-trip primitive integer and boolean types
    let orig_u32 = 0x1234_5678_u32;
    let ule_u32: RawBytesULE<4> = orig_u32.to_unaligned();
    assert_eq!(ule_u32.as_bytes(), &[0x78, 0x56, 0x34, 0x12]);
    let recovered_u32 = u32::from_unaligned(ule_u32);
    assert_eq!(recovered_u32, orig_u32);

    let orig_bool = true;
    let ule_bool = orig_bool.to_unaligned();
    assert_eq!(bool::from_unaligned(ule_bool), true);

    let orig_i64 = -42_i64;
    let ule_i64 = orig_i64.to_unaligned();
    assert_eq!(i64::from_unaligned(ule_i64), orig_i64);

    // 2. AsULE converts char to CharULE validating 3-byte little-endian Unicode scalar values
    let orig_char = '🦀';
    let ule_char: CharULE = orig_char.to_unaligned();
    let char_array = [ule_char];
    let char_bytes = CharULE::slice_as_bytes(&char_array);
    assert_eq!(char_bytes.len(), 3);
    assert_eq!(char::from_unaligned(ule_char), orig_char);

    // 3. AsULE is implemented for fixed-size arrays and tuples preserving element-wise unaligned conversion
    let orig_arr: [u16; 3] = [10, 20, 30];
    let ule_arr = orig_arr.to_unaligned();
    assert_eq!(<[u16; 3]>::from_unaligned(ule_arr), orig_arr);

    let orig_tuple: (u8, u32) = (7, 1000);
    let ule_tuple = orig_tuple.to_unaligned();
    assert_eq!(<(u8, u32)>::from_unaligned(ule_tuple), orig_tuple);

    // 4. AsULE enables zero-copy representation for Option<T> via OptionULE distinguishing Some and None
    let some_opt: Option<u32> = Some(999);
    let none_opt: Option<u32> = None;
    let ule_some: OptionULE<RawBytesULE<4>> = some_opt.to_unaligned();
    let ule_none: OptionULE<RawBytesULE<4>> = none_opt.to_unaligned();
    assert_eq!(Option::<u32>::from_unaligned(ule_some), Some(999));
    assert_eq!(Option::<u32>::from_unaligned(ule_none), None);

    // 5. Custom types implementing AsULE can be stored and retrieved zero-copy in ZeroVec
    let ules: [CoordinateULE; 3] = [
        Coordinate { x: 10, y: -20 }.to_unaligned(),
        Coordinate { x: 30, y: 40 }.to_unaligned(),
        Coordinate { x: -5, y: 15 }.to_unaligned(),
    ];
    let zv: ZeroVec<Coordinate> = ZeroVec::new_borrowed(&ules);
    assert_eq!(zv.len(), 3);
    assert_eq!(zv.get(0), Some(Coordinate { x: 10, y: -20 }));
    assert_eq!(zv.get(1), Some(Coordinate { x: 30, y: 40 }));
    assert_eq!(zv.get(2), Some(Coordinate { x: -5, y: 15 }));
    assert_eq!(zv.get(3), None);

    // Verify zero-copy byte slice roundtrip
    let raw_bytes: &[u8] = zv.as_bytes();
    let parsed_zv: ZeroVec<Coordinate> = ZeroVec::parse_bytes(raw_bytes).expect("valid bytes");
    assert_eq!(parsed_zv.len(), 3);
    assert_eq!(parsed_zv.get(0), zv.get(0));
    assert_eq!(parsed_zv.get(1), zv.get(1));
    assert_eq!(parsed_zv.get(2), zv.get(2));

    println!("All zerovec::ule::AsULE contract assertions passed successfully.");
}

Origin Seeder

anonymous