Beispiel
zerovec 0.11.6: zerovec::ule::AsULE
Verifiziertes Beispiel für cargo zerovec 0.11.6: zerovec::ule::AsULE. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand.
sha256:6f7fce7244ddff6e57aff33a5b29821fab1cc7287267606d64f8bbb64e4b0ca3
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 · alpine · musl x64 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-09-21 |
Fall
HOW- Ziel
- verify zerovec::ule::AsULE in pkg:cargo/zerovec@0.11.6
- Pakete
- Symbole
-
- zerovec::ule::AsULE
- Erstellt
- 2026-09-21T08:16:16Z
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<T> via OptionULE distinguishing Some and None
- Custom types implementing AsULE can be stored and retrieved zero-copy in ZeroVec
Dateien
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Quelltext
# 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",
]
[package]
name = "sample-zerovec"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
zerovec = "=0.11.6"
[[bin]]
name = "contract"
path = "test/contract.rs"
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.
{"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"}
{
"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"
]
}
//! Clean-room verification sample for zerovec.
pub use zerovec::*;
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.");
}
Ursprungs-Seeder
anonym