CodeSampleX

Exemplo

utf8_iter 1.0.4

Amostra verificada para cargo utf8_iter 1.0.4. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou: Utf8Chars iterates over valid UTF-8 byte…

sha256:b3aa7576ee65d32e82dc45baefc108ce4e2a3310c5e19fd19b17c36a4221d7eb

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-09-19

Caso

HOW
Objetivo
verify pkg:cargo/utf8_iter@1.0.4
Pacotes
Criado
2026-09-18T13:30:37Z

Contrato

  1. Utf8Chars iterates over valid UTF-8 byte slices yielding decoded characters
  2. Utf8Chars replaces invalid UTF-8 byte sequences with Unicode replacement characters per WHATWG specification
  3. Utf8CharsEx trait provides chars and char_indices methods directly on byte slices
  4. Utf8Chars implements DoubleEndedIterator supporting reverse iteration over byte slices
  5. Utf8CharIndices provides byte offsets alongside decoded characters
  6. ErrorReportingUtf8Chars yields Ok(char) for valid code points and Err(Utf8CharsError) on invalid byte sequences

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-utf8-iter"
version = "1.0.0"
dependencies = [
 "utf8_iter",
]

[[package]]
name = "utf8_iter"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
Cargo.toml
[package]
name = "sample-utf8-iter"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
utf8_iter = "=1.0.4"

[[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/utf8_iter@1.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/utf8_iter@1.0.4

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:a0e564f4a2a56af558b784a0d267aec32f5c09a33822de5e0eb6b610720e8b96","contract":["Utf8Chars iterates over valid UTF-8 byte slices yielding decoded characters","Utf8Chars replaces invalid UTF-8 byte sequences with Unicode replacement characters per WHATWG specification","Utf8CharsEx trait provides chars and char_indices methods directly on byte slices","Utf8Chars implements DoubleEndedIterator supporting reverse iteration over byte slices","Utf8CharIndices provides byte offsets alongside decoded characters","ErrorReportingUtf8Chars yields Ok(char) for valid code points and Err(Utf8CharsError) on invalid byte sequences"],"goal":"verify pkg:cargo/utf8_iter@1.0.4","kind":"HOW","packages":["pkg:cargo/utf8_iter@1.0.4"],"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/utf8_iter@1.0.4"],"schemaVersion":1,"subject":"pkg:cargo/utf8_iter@1.0.4","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/utf8_iter@1.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/utf8_iter@1.0.4"
  ]
}
src/lib.rs
//! Clean-room verification sample for utf8_iter.

pub use utf8_iter::*;
test/contract.rs
use utf8_iter::{ErrorReportingUtf8Chars, Utf8Chars, Utf8CharsEx};

fn main() {
    // 1. Utf8Chars iterates over valid UTF-8 byte slices yielding decoded characters
    let valid_bytes = "Hello, 世界! 🦀".as_bytes();
    let mut iter = Utf8Chars::new(valid_bytes);
    assert_eq!(iter.next(), Some('H'));
    assert_eq!(iter.next(), Some('e'));
    assert_eq!(iter.next(), Some('l'));
    assert_eq!(iter.next(), Some('l'));
    assert_eq!(iter.next(), Some('o'));
    assert_eq!(iter.next(), Some(','));
    assert_eq!(iter.next(), Some(' '));
    assert_eq!(iter.next(), Some('世'));
    assert_eq!(iter.next(), Some('界'));
    assert_eq!(iter.next(), Some('!'));
    assert_eq!(iter.next(), Some(' '));
    assert_eq!(iter.next(), Some('🦀'));
    assert_eq!(iter.next(), None);

    let mut slice_test = Utf8Chars::new(b"abc");
    assert_eq!(slice_test.as_slice(), b"abc");
    assert_eq!(slice_test.next(), Some('a'));
    assert_eq!(slice_test.as_slice(), b"bc");

    // 2. Utf8Chars replaces invalid UTF-8 byte sequences with Unicode replacement characters per WHATWG specification
    let invalid_bytes = b"foo\xFFbar\xC0\xAFbaz";
    let chars: Vec<char> = Utf8Chars::new(invalid_bytes).collect();
    assert_eq!(chars, vec!['f', 'o', 'o', '\u{FFFD}', 'b', 'a', 'r', '\u{FFFD}', '\u{FFFD}', 'b', 'a', 'z']);

    // 3. Utf8CharsEx trait provides chars and char_indices methods directly on byte slices
    let ex_bytes = b"rust-lang";
    let mut ex_iter = ex_bytes.chars();
    assert_eq!(ex_iter.next(), Some('r'));
    assert_eq!(ex_iter.next(), Some('u'));
    assert_eq!(ex_iter.next(), Some('s'));
    assert_eq!(ex_iter.next(), Some('t'));

    let mut idx_iter = ex_bytes.char_indices();
    assert_eq!(idx_iter.next(), Some((0, 'r')));
    assert_eq!(idx_iter.next(), Some((1, 'u')));

    // 4. Utf8Chars implements DoubleEndedIterator supporting reverse iteration over byte slices
    let rev_bytes = "abc".as_bytes();
    let mut rev_iter = Utf8Chars::new(rev_bytes);
    assert_eq!(rev_iter.next_back(), Some('c'));
    assert_eq!(rev_iter.next_back(), Some('b'));
    assert_eq!(rev_iter.next_back(), Some('a'));
    assert_eq!(rev_iter.next_back(), None);

    // 5. Utf8CharIndices provides byte offsets alongside decoded characters
    let multi_byte = "a🦀b".as_bytes();
    let indices: Vec<(usize, char)> = multi_byte.char_indices().collect();
    assert_eq!(indices, vec![(0, 'a'), (1, '🦀'), (5, 'b')]);

    // 6. ErrorReportingUtf8Chars yields Ok(char) for valid code points and Err(Utf8CharsError) on invalid byte sequences
    let mixed_bytes = b"a\xFFb";
    let mut report_iter = ErrorReportingUtf8Chars::new(mixed_bytes);
    assert_eq!(report_iter.next(), Some(Ok('a')));
    let err = report_iter.next().unwrap().unwrap_err();
    assert_eq!(err.to_string(), "byte sequence not well-formed UTF-8");
    assert_eq!(report_iter.next(), Some(Ok('b')));
    assert_eq!(report_iter.next(), None);

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

Seeder de origem

anônimo