CodeSampleX

Exemplo

equivalent 1.0.3: equivalent::Comparable, equivalent::Equivalent

Amostra verificada para cargo equivalent 1.0.3: equivalent::Comparable, equivalent::Equivalent. O contrato rodou em rust 1 · linux alpine/x64 · docker e…

sha256:5b08dcca1377296f917decc5dc86b8f38d56affc0d10f402e24a37e2b0efd6fb

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 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-05

Caso

HOW
Objetivo
verify pkg:cargo/equivalent@1.0.3
Pacotes
Símbolos
  • equivalent::Comparable
  • equivalent::Equivalent
Criado
2026-11-05T20:17:21Z

Contrato

  1. Equivalent::equivalent returns true when a borrowed PairQuery matches an owned PairKey and false otherwise
  2. Comparable::compare orders a borrowed PairQuery against an owned PairKey lexicographically by namespace and name
  3. Blanket Equivalent and Comparable implementations on str and String report equality and Ordering::Equal

Arquivos

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • src/main.rs
  • tests/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 = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"

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

[dependencies]
equivalent = "=1.0.3"
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/equivalent@1.0.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/equivalent@1.0.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:6e9c8cd011bf9e4e41e7593374fa3d06596fa2b56a78cf1a0b439028a2b8eda7","contract":["Equivalent::equivalent returns true when a borrowed PairQuery matches an owned PairKey and false otherwise","Comparable::compare orders a borrowed PairQuery against an owned PairKey lexicographically by namespace and name","Blanket Equivalent and Comparable implementations on str and String report equality and Ordering::Equal"],"goal":"verify pkg:cargo/equivalent@1.0.3","kind":"HOW","packages":["pkg:cargo/equivalent@1.0.3"],"schemaVersion":1,"symbols":["equivalent::Comparable","equivalent::Equivalent"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/equivalent@1.0.3"],"schemaVersion":1,"subject":"pkg:cargo/equivalent@1.0.3","symbols":["equivalent::Comparable","equivalent::Equivalent"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/equivalent@1.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/equivalent@1.0.3"
  ]
}
src/lib.rs
use core::cmp::Ordering;
use equivalent::{Comparable, Equivalent};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct PairKey {
    pub namespace: String,
    pub name: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct PairQuery<'a> {
    pub namespace: &'a str,
    pub name: &'a str,
}

impl Equivalent<PairKey> for PairQuery<'_> {
    fn equivalent(&self, key: &PairKey) -> bool {
        self.namespace == key.namespace && self.name == key.name
    }
}

impl Comparable<PairKey> for PairQuery<'_> {
    fn compare(&self, key: &PairKey) -> Ordering {
        match self.namespace.cmp(&key.namespace) {
            Ordering::Equal => self.name.cmp(&key.name),
            ord => ord,
        }
    }
}

pub fn lookup_value<'v, Q>(entries: &'v [(PairKey, i32)], query: &Q) -> Option<i32>
where
    Q: Equivalent<PairKey> + ?Sized,
{
    entries
        .iter()
        .find(|(k, _)| query.equivalent(k))
        .map(|(_, v)| *v)
}

pub fn binary_search_value<Q>(sorted_entries: &[(PairKey, i32)], query: &Q) -> Option<i32>
where
    Q: Comparable<PairKey> + ?Sized,
{
    sorted_entries
        .binary_search_by(|(k, _)| query.compare(k).reverse())
        .ok()
        .map(|idx| sorted_entries[idx].1)
}
src/main.rs
use core::cmp::Ordering;
use equivalent::{Comparable, Equivalent};
use equivalent_sample::{binary_search_value, lookup_value, PairKey, PairQuery};

fn main() {
    let entries = vec![
        (
            PairKey {
                namespace: "alpha".to_string(),
                name: "first".to_string(),
            },
            10,
        ),
        (
            PairKey {
                namespace: "beta".to_string(),
                name: "second".to_string(),
            },
            20,
        ),
    ];

    let q_hit = PairQuery {
        namespace: "alpha",
        name: "first",
    };
    let q_miss = PairQuery {
        namespace: "alpha",
        name: "other",
    };

    assert!(q_hit.equivalent(&entries[0].0));
    assert!(!q_miss.equivalent(&entries[0].0));
    assert_eq!(q_hit.compare(&entries[0].0), Ordering::Equal);
    assert_eq!(q_hit.compare(&entries[1].0), Ordering::Less);

    assert_eq!(lookup_value(&entries, &q_hit), Some(10));
    assert_eq!(lookup_value(&entries, &q_miss), None);
    assert_eq!(binary_search_value(&entries, &q_hit), Some(10));
    assert_eq!(binary_search_value(&entries, &q_miss), None);

    let owned = String::from("hello");
    assert!(Equivalent::equivalent("hello", &owned));
    assert_eq!(Comparable::compare("hello", &owned), Ordering::Equal);
}
tests/contract.rs
use core::cmp::Ordering;
use equivalent::{Comparable, Equivalent};
use equivalent_sample::{binary_search_value, lookup_value, PairKey, PairQuery};

#[test]
fn contract_equivalent_and_comparable() {
    let entries = vec![
        (
            PairKey {
                namespace: "alpha".to_string(),
                name: "first".to_string(),
            },
            10,
        ),
        (
            PairKey {
                namespace: "beta".to_string(),
                name: "second".to_string(),
            },
            20,
        ),
    ];

    let q_hit = PairQuery {
        namespace: "alpha",
        name: "first",
    };
    let q_miss = PairQuery {
        namespace: "alpha",
        name: "other",
    };

    assert!(q_hit.equivalent(&entries[0].0));
    assert!(!q_miss.equivalent(&entries[0].0));
    assert_eq!(q_hit.compare(&entries[0].0), Ordering::Equal);
    assert_eq!(q_hit.compare(&entries[1].0), Ordering::Less);

    assert_eq!(lookup_value(&entries, &q_hit), Some(10));
    assert_eq!(lookup_value(&entries, &q_miss), None);
    assert_eq!(binary_search_value(&entries, &q_hit), Some(10));
    assert_eq!(binary_search_value(&entries, &q_miss), None);

    let owned = String::from("hello");
    assert!(Equivalent::equivalent("hello", &owned));
    assert_eq!(Comparable::compare("hello", &owned), Ordering::Equal);
}

Seeder de origem

anônimo