CodeSampleX

Exemplo

tinyvec 1.12.0: tinyvec::ArrayVec

Amostra verificada para cargo tinyvec 1.12.0: tinyvec::ArrayVec. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou.

sha256:bdbf45465ce3e490132bbbdb9a9e158d056b9d05822c09a786d290eaf0f8f21b

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux · alpine · musl x64 cargo

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-11-22

Caso

HOW
Objetivo
verify tinyvec::ArrayVec in pkg:cargo/tinyvec@1.12.0
Pacotes
Símbolos
  • tinyvec::ArrayVec
Criado
2026-11-21T20:39:03Z

Contrato

  1. ArrayVec::new creates an empty stack-allocated vector with fixed capacity
  2. push and try_push append elements up to capacity and try_push returns Some(val) when full
  3. pop, insert, remove, and swap_remove mutate elements while preserving order/invariants
  4. extend_from_slice, retain, truncate, and clear update length and contents
  5. from_array_len, From<[T; N]>, split_off, and into_iter construct, split, and consume ArrayVec values

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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

[[package]]
name = "sample-tinyvec-arrayvec"
version = "0.1.0"
dependencies = [
 "tinyvec",
]

[[package]]
name = "tinyvec"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f"
Cargo.toml
[package]
name = "sample-tinyvec-arrayvec"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
tinyvec = "=1.12.0"

[[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 tinyvec::ArrayVec in pkg:cargo/tinyvec@1.12.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/tinyvec@1.12.0
Demonstrate these symbols/APIs:
  - tinyvec::ArrayVec

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:068d77258f5b34960d6e63f3861b6174086ab838371e8c466b35bed4b57a55d9","contract":["ArrayVec::new creates an empty stack-allocated vector with fixed capacity","push and try_push append elements up to capacity and try_push returns Some(val) when full","pop, insert, remove, and swap_remove mutate elements while preserving order/invariants","extend_from_slice, retain, truncate, and clear update length and contents","from_array_len, From\u003c[T; N]\u003e, split_off, and into_iter construct, split, and consume ArrayVec values"],"goal":"verify tinyvec::ArrayVec in pkg:cargo/tinyvec@1.12.0","kind":"HOW","packages":["pkg:cargo/tinyvec@1.12.0"],"schemaVersion":1,"symbols":["tinyvec::ArrayVec"]},"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/tinyvec@1.12.0"],"schemaVersion":1,"subject":"pkg:cargo/tinyvec@1.12.0","symbols":["tinyvec::ArrayVec"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify tinyvec::ArrayVec in pkg:cargo/tinyvec@1.12.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/tinyvec@1.12.0"
  ],
  "symbols": [
    "tinyvec::ArrayVec"
  ]
}
src/lib.rs
//! Clean-room verification sample for tinyvec::ArrayVec.

pub use tinyvec::ArrayVec;
test/contract.rs
use tinyvec::ArrayVec;

fn main() {
    // 1. ArrayVec::new creates an empty stack-allocated vector with fixed capacity
    let mut vec = ArrayVec::<[i32; 4]>::new();
    assert!(vec.is_empty());
    assert_eq!(vec.len(), 0);
    assert_eq!(vec.capacity(), 4);
    assert_eq!(vec.as_slice(), &[]);

    // 2. push and try_push append elements up to capacity and return overflow on try_push
    vec.push(10);
    vec.push(20);
    assert_eq!(vec.try_push(30), None);
    assert_eq!(vec.try_push(40), None);
    assert_eq!(vec.len(), 4);
    assert_eq!(vec.as_slice(), &[10, 20, 30, 40]);
    assert_eq!(vec.try_push(50), Some(50));
    assert_eq!(vec.as_slice(), &[10, 20, 30, 40]);

    // 3. pop, insert, remove, and swap_remove mutate elements while preserving invariants
    assert_eq!(vec.pop(), Some(40));
    assert_eq!(vec.as_slice(), &[10, 20, 30]);

    vec.insert(1, 15);
    assert_eq!(vec.as_slice(), &[10, 15, 20, 30]);

    assert_eq!(vec.remove(2), 20);
    assert_eq!(vec.as_slice(), &[10, 15, 30]);

    assert_eq!(vec.swap_remove(0), 10);
    assert_eq!(vec.as_slice(), &[30, 15]);

    // 4. retain, truncate, extend_from_slice, and clear update length and contents
    vec.extend_from_slice(&[5, 25]);
    assert_eq!(vec.as_slice(), &[30, 15, 5, 25]);

    vec.retain(|&x| x >= 15);
    assert_eq!(vec.as_slice(), &[30, 15, 25]);

    vec.truncate(2);
    assert_eq!(vec.as_slice(), &[30, 15]);

    vec.clear();
    assert!(vec.is_empty());
    assert_eq!(vec.pop(), None);

    // 5. from_array_len, From<[T; N]>, split_off, and into_iter work as expected
    let mut from_len = ArrayVec::from_array_len([1, 2, 3, 0, 0], 3);
    assert_eq!(from_len.len(), 3);
    assert_eq!(from_len.capacity(), 5);
    assert_eq!(from_len.as_slice(), &[1, 2, 3]);

    let right = from_len.split_off(1);
    assert_eq!(from_len.as_slice(), &[1]);
    assert_eq!(right.as_slice(), &[2, 3]);

    let full = ArrayVec::from([7, 8, 9]);
    assert_eq!(full.len(), 3);
    let collected: Vec<i32> = full.into_iter().collect();
    assert_eq!(collected, vec![7, 8, 9]);

    println!("All tinyvec::ArrayVec contract assertions passed.");
}

Seeder de origem

anônimo