CodeSampleX

Ejemplo

socket2 0.6.5: socket2::Type

Muestra verificada para cargo socket2 0.6.5: socket2::Type. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó.

sha256:886656c0294e551e0017e6ea94296a91bf45b1f465659c0cd4c8a275c6849fbf

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux · alpine · musl x64 cargo

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-20

Caso

HOW
Objetivo
verify socket2::Type in pkg:cargo/socket2@0.6.5
Paquetes
Símbolos
  • socket2::Type
Creado
2026-09-20T16:27:44Z

Contrato

  1. Type::STREAM and Type::DGRAM provide distinct standard socket type constants
  2. Type::SEQPACKET, Type::RAW, and Type::DCCP provide extended socket types
  3. Type::nonblocking and Type::cloexec modify socket type flags
  4. Type converts to and from raw integer representation using From and Into
  5. Type supports Copy, Clone, and equality comparisons

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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

[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"

[[package]]
name = "sample-socket2"
version = "1.0.0"
dependencies = [
 "socket2",
]

[[package]]
name = "socket2"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
 "libc",
 "windows-sys",
]

[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"

[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
 "windows-link",
]
Cargo.toml
[package]
name = "sample-socket2"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
socket2 = { version = "=0.6.5", features = ["all"] }

[[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 socket2::Type in pkg:cargo/socket2@0.6.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/socket2@0.6.5
Demonstrate these symbols/APIs:
  - socket2::Type

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:2f72509819a814ead549af3b29bd005548398d6efd41283d86dadee2a6db8a75","contract":["Type::STREAM and Type::DGRAM provide distinct standard socket type constants","Type::SEQPACKET, Type::RAW, and Type::DCCP provide extended socket types","Type::nonblocking and Type::cloexec modify socket type flags","Type converts to and from raw integer representation using From and Into","Type supports Copy, Clone, and equality comparisons"],"goal":"verify socket2::Type in pkg:cargo/socket2@0.6.5","kind":"HOW","packages":["pkg:cargo/socket2@0.6.5"],"schemaVersion":1,"symbols":["socket2::Type"]},"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/socket2@0.6.5"],"schemaVersion":1,"subject":"pkg:cargo/socket2@0.6.5","symbols":["socket2::Type"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify socket2::Type in pkg:cargo/socket2@0.6.5",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/socket2@0.6.5"
  ],
  "symbols": [
    "socket2::Type"
  ]
}
src/lib.rs
//! Clean-room verification sample for socket2.

pub use socket2::*;
test/contract.rs
use socket2::Type;

fn main() {
    // 1. Type::STREAM and Type::DGRAM provide distinct standard socket type constants
    let stream = Type::STREAM;
    let dgram = Type::DGRAM;
    assert_eq!(stream, Type::STREAM);
    assert_ne!(stream, dgram);

    // 2. Type::SEQPACKET, Type::RAW, and Type::DCCP provide extended socket types
    let seqpacket = Type::SEQPACKET;
    let raw = Type::RAW;
    let dccp = Type::DCCP;
    assert_ne!(stream, seqpacket);
    assert_ne!(stream, raw);
    assert_ne!(stream, dccp);

    // 3. Type::nonblocking and Type::cloexec modify socket type flags
    let stream_nb = stream.nonblocking();
    let stream_cloexec = stream.cloexec();
    let stream_both = stream.nonblocking().cloexec();
    assert_ne!(stream, stream_nb);
    assert_ne!(stream, stream_cloexec);
    assert_ne!(stream_nb, stream_both);

    // 4. Type converts to and from raw integer representation using From and Into
    let raw_int: std::ffi::c_int = stream.into();
    let reconstructed = Type::from(raw_int);
    assert_eq!(stream, reconstructed);

    let raw_int_dgram: std::ffi::c_int = dgram.into();
    let reconstructed_dgram = Type::from(raw_int_dgram);
    assert_eq!(dgram, reconstructed_dgram);

    // 5. Type supports Copy, Clone, and equality comparisons
    let copy_type = stream;
    assert_eq!(copy_type, stream);

    println!("All socket2::Type contract assertions passed successfully.");
}

Seeder de origen

anónimo