CodeSampleX

示例

zerovec 0.11.6: zerovec::ule::CharULE

已验证示例 — cargo zerovec 0.11.6: zerovec::ule::CharULE. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: CharULE converts to and from char directly and via…

sha256:cebd8b3a34c0864676df311621f7cfdb8cbddbe780f5a381036718a6304800e2

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-09-21

案例

HOW
目标
verify zerovec::ule::CharULE in pkg:cargo/zerovec@0.11.6
包
符号
  • zerovec::ule::CharULE
创建时间
2026-09-21T12:36:50Z

契约

  1. CharULE converts to and from char directly and via AsULE trait
  2. CharULE encodes characters as 3 little-endian bytes without padding
  3. CharULE parses and validates byte slices rejecting non-multiple of 3 lengths and invalid codepoints
  4. CharULE preserves character equality and ordering semantics
  5. ZeroVec stores characters as unaligned CharULE elements

文件

  • 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 = "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::CharULE 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::CharULE

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:57cf464e14a2aab3162ac0e80051512802bdeed00292ccb514b2acd97d3b657c","contract":["CharULE converts to and from char directly and via AsULE trait","CharULE encodes characters as 3 little-endian bytes without padding","CharULE parses and validates byte slices rejecting non-multiple of 3 lengths and invalid codepoints","CharULE preserves character equality and ordering semantics","ZeroVec stores characters as unaligned CharULE elements"],"goal":"verify zerovec::ule::CharULE in pkg:cargo/zerovec@0.11.6","kind":"HOW","packages":["pkg:cargo/zerovec@0.11.6"],"schemaVersion":1,"symbols":["zerovec::ule::CharULE"]},"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::CharULE"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify zerovec::ule::CharULE in pkg:cargo/zerovec@0.11.6",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/zerovec@0.11.6"
  ],
  "symbols": [
    "zerovec::ule::CharULE"
  ]
}
src/lib.rs
//! Clean-room verification sample for zerovec.

pub use zerovec::*;
test/contract.rs
use std::cmp::Ordering;
use zerovec::ule::{AsULE, CharULE, ULE};
use zerovec::ZeroVec;

fn main() {
    // 1. CharULE converts to and from char directly and via AsULE trait
    let c = '🦀';
    let ule_direct = CharULE::from_aligned(c);
    assert_eq!(ule_direct.to_char(), c);

    let ule_trait: CharULE = c.to_unaligned();
    assert_eq!(char::from_unaligned(ule_trait), c);
    assert_eq!(ule_direct, ule_trait);

    let chars = ['a', 'Ω', '文', '🦀'];
    for &ch in &chars {
        let ule = ch.to_unaligned();
        assert_eq!(char::from_unaligned(ule), ch);
        assert_eq!(ule.to_char(), ch);
    }

    // 2. CharULE encodes characters as 3 little-endian bytes without padding
    let ascii_slice = ['a'.to_unaligned()];
    let ascii_bytes = CharULE::slice_as_bytes(&ascii_slice);
    assert_eq!(ascii_bytes, &[0x61, 0x00, 0x00]);

    // Crab emoji U+1F980 -> LE bytes: 0x80, 0xF9, 0x01
    let crab_slice = ['🦀'.to_unaligned()];
    let crab_bytes = CharULE::slice_as_bytes(&crab_slice);
    assert_eq!(crab_bytes, &[0x80, 0xF9, 0x01]);

    const ARRAY_CHARS: [char; 2] = ['a', 'b'];
    const ARRAY_ULES: [CharULE; 2] = CharULE::from_array(ARRAY_CHARS);
    assert_eq!(CharULE::slice_as_bytes(&ARRAY_ULES), &[0x61, 0x00, 0x00, 0x62, 0x00, 0x00]);

    // 3. CharULE parses and validates byte slices rejecting non-multiple of 3 lengths and invalid codepoints
    let valid_bytes = [0x61, 0x00, 0x00, 0x80, 0xF9, 0x01];
    let parsed = CharULE::parse_bytes_to_slice(&valid_bytes).expect("valid bytes");
    assert_eq!(parsed.len(), 2);
    assert_eq!(parsed[0].to_char(), 'a');
    assert_eq!(parsed[1].to_char(), '🦀');

    // Length not multiple of 3
    assert!(CharULE::parse_bytes_to_slice(&[0x61, 0x00]).is_err());
    assert!(CharULE::validate_bytes(&[0x61, 0x00]).is_err());

    // Surrogate codepoint 0xD800 (high surrogate) -> LE: 0x00, 0xD8, 0x00
    let surrogate_bytes = [0x00, 0xD8, 0x00];
    assert!(CharULE::parse_bytes_to_slice(&surrogate_bytes).is_err());
    assert!(CharULE::validate_bytes(&surrogate_bytes).is_err());

    // Out of range codepoint 0x20FFFF -> LE: 0xFF, 0xFF, 0x20
    let out_of_range = [0xFF, 0xFF, 0x20];
    assert!(CharULE::parse_bytes_to_slice(&out_of_range).is_err());
    assert!(CharULE::validate_bytes(&out_of_range).is_err());

    // 4. CharULE preserves character equality and ordering semantics
    let ule_a = 'a'.to_unaligned();
    let ule_b = 'b'.to_unaligned();
    let ule_a2 = 'a'.to_unaligned();

    assert_eq!(ule_a, ule_a2);
    assert_ne!(ule_a, ule_b);
    assert_eq!(ule_a.cmp(&ule_b), Ordering::Less);
    assert_eq!(ule_b.cmp(&ule_a), Ordering::Greater);
    assert_eq!(ule_a.cmp(&ule_a2), Ordering::Equal);
    assert!(ule_a < ule_b);

    // 5. ZeroVec stores characters as unaligned CharULE elements
    let zv = ZeroVec::<char>::parse_bytes(&valid_bytes).expect("valid zerovec bytes");
    assert_eq!(zv.get(0), Some('a'));
    assert_eq!(zv.get(1), Some('🦀'));
    assert_eq!(zv.get(2), None);
    assert_eq!(zv.as_bytes(), &valid_bytes);

    let zv_borrowed: ZeroVec<char> = ZeroVec::new_borrowed(&ARRAY_ULES);
    assert_eq!(zv_borrowed.get(0), Some('a'));
    assert_eq!(zv_borrowed.get(1), Some('b'));
    assert_eq!(zv_borrowed.get(2), None);

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

原始种子者

匿名