CodeSampleX

示例

litemap 0.8.3

已验证示例 — cargo litemap 0.8.3. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: LiteMap creates empty vector-backed map and reports length, emptiness, and…

sha256:b04e14e60b1dfeba6f6a529986e9fc32594093b8ceb63f934d7a54f2e7440f77

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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-19

案例

HOW
目标
verify pkg:cargo/litemap@0.8.3
包
创建时间
2026-09-18T13:35:13Z

契约

  1. LiteMap creates empty vector-backed map and reports length, emptiness, and capacity
  2. LiteMap inserts key-value pairs maintaining sorted order and replaces existing keys returning previous value
  3. LiteMap retrieves values by key reference, supports contains_key, and provides mutable access via get_mut
  4. LiteMap removes entries by key, supports try_insert and try_append preserving sort invariants, and clears elements
  5. LiteMap provides entry API for in-place vacant and occupied entry manipulation

文件

  • 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 = "litemap"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"

[[package]]
name = "sample-litemap"
version = "1.0.0"
dependencies = [
 "litemap",
]
Cargo.toml
[package]
name = "sample-litemap"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
litemap = "=0.8.3"

[[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/litemap@0.8.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/litemap@0.8.3

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:cd3ae638056cd0d28f5a5c1bd81f28f050778206b56901beb3bc291c23dd655e","contract":["LiteMap creates empty vector-backed map and reports length, emptiness, and capacity","LiteMap inserts key-value pairs maintaining sorted order and replaces existing keys returning previous value","LiteMap retrieves values by key reference, supports contains_key, and provides mutable access via get_mut","LiteMap removes entries by key, supports try_insert and try_append preserving sort invariants, and clears elements","LiteMap provides entry API for in-place vacant and occupied entry manipulation"],"goal":"verify pkg:cargo/litemap@0.8.3","kind":"HOW","packages":["pkg:cargo/litemap@0.8.3"],"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/litemap@0.8.3"],"schemaVersion":1,"subject":"pkg:cargo/litemap@0.8.3","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/litemap@0.8.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/litemap@0.8.3"
  ]
}
src/lib.rs
//! Clean-room verification sample for litemap.

pub use litemap::*;
test/contract.rs
use litemap::{Entry, LiteMap};

fn main() {
    // 1. LiteMap creates empty vector-backed map and reports length, emptiness, and capacity
    let mut map: LiteMap<i32, &str> = LiteMap::new_vec();
    assert!(map.is_empty());
    assert_eq!(map.len(), 0);
    assert_eq!(map.first(), None);
    assert_eq!(map.last(), None);

    let mut cap_map: LiteMap<i32, &str> = LiteMap::with_capacity(10);
    assert!(cap_map.is_empty());
    assert_eq!(cap_map.len(), 0);
    cap_map.reserve(5);

    // 2. LiteMap inserts key-value pairs maintaining sorted order and replaces existing keys returning previous value
    assert_eq!(map.insert(30, "thirty"), None);
    assert_eq!(map.insert(10, "ten"), None);
    assert_eq!(map.insert(20, "twenty"), None);
    assert_eq!(map.len(), 3);
    assert!(!map.is_empty());

    // Sorted order: 10, 20, 30
    assert_eq!(map.first(), Some((&10, &"ten")));
    assert_eq!(map.last(), Some((&30, &"thirty")));
    assert_eq!(map.get_indexed(1), Some((&20, &"twenty")));

    // Replace existing key
    let old = map.insert(20, "twenty-updated");
    assert_eq!(old, Some("twenty"));
    assert_eq!(map.get(&20), Some(&"twenty-updated"));
    assert_eq!(map.len(), 3);

    // 3. LiteMap retrieves values by key reference, supports contains_key, and provides mutable access via get_mut
    assert!(map.contains_key(&10));
    assert!(map.contains_key(&20));
    assert!(map.contains_key(&30));
    assert!(!map.contains_key(&40));

    assert_eq!(map.get(&10), Some(&"ten"));
    assert_eq!(map.get(&40), None);

    if let Some(v) = map.get_mut(&10) {
        *v = "diez";
    }
    assert_eq!(map.get(&10), Some(&"diez"));

    let slice = map.as_slice();
    assert_eq!(slice, &[(10, "diez"), (20, "twenty-updated"), (30, "thirty")]);

    // 4. LiteMap removes entries by key, supports try_insert and try_append preserving sort invariants, and clears elements
    assert_eq!(map.try_insert(20, "duplicate"), Some((20, "duplicate")));
    assert_eq!(map.try_insert(25, "twenty-five"), None);
    assert_eq!(map.len(), 4);

    // try_append: only succeeds if strictly greater than last key
    assert_eq!(map.try_append(15, "fifteen"), Some((15, "fifteen")));
    assert_eq!(map.try_append(50, "fifty"), None);
    assert_eq!(map.len(), 5);

    let removed = map.remove(&25);
    assert_eq!(removed, Some("twenty-five"));
    assert_eq!(map.remove(&999), None);
    assert_eq!(map.len(), 4);

    let mut clearable: LiteMap<i32, &str> = LiteMap::new_vec();
    clearable.insert(1, "one");
    clearable.clear();
    assert!(clearable.is_empty());
    assert_eq!(clearable.len(), 0);

    // 5. LiteMap provides entry API for in-place vacant and occupied entry manipulation
    match map.entry(50) {
        Entry::Occupied(mut occ) => {
            assert_eq!(*occ.get(), "fifty");
            *occ.get_mut() = "fifty-modified";
        }
        Entry::Vacant(_) => panic!("expected occupied entry for 50"),
    }
    assert_eq!(map.get(&50), Some(&"fifty-modified"));

    match map.entry(100) {
        Entry::Vacant(vac) => {
            vac.insert("one-hundred");
        }
        Entry::Occupied(_) => panic!("expected vacant entry for 100"),
    }
    assert_eq!(map.get(&100), Some(&"one-hundred"));

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

原始种子者

匿名