CodeSampleX

Exemplo

socket2 0.6.5: socket2::SockAddr

Amostra verificada para cargo socket2 0.6.5: socket2::SockAddr. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou.

sha256:19a7c92839a8bdaa2c761d1f98d2c63fe3fd8e03b0af96bca2d58c4ecf680749

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

Caso

HOW
Objetivo
verify socket2::SockAddr in pkg:cargo/socket2@0.6.5
Pacotes
Símbolos
  • socket2::SockAddr
Criado
2026-09-20T17:59:22Z

Contrato

  1. SockAddr from SocketAddrV4 creates an IPv4 address with Domain::IPV4 and matches as_socket_ipv4
  2. SockAddr from SocketAddrV6 creates an IPv6 address with Domain::IPV6 and matches as_socket_ipv6
  3. SockAddr from generic SocketAddr enum preserves IPv4 and IPv6 representations
  4. SockAddr::unix creates a Unix domain socket address with Domain::UNIX matching as_pathname
  5. SockAddr implements Clone, PartialEq, and Debug formatting

Arquivos

  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • 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 = "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 = "=0.6.5"

[[bin]]
name = "contract"
path = "test/contract.rs"
NOTES.md
# socket2 0.6.5 SockAddr API Contracts

## What `search_known_solution` answered
`search_known_solution` returned NO_SAFE_MATCH for socket2::SockAddr in pkg:cargo/socket2@0.6.5.

## What a model would have written instead
A model may attempt to call deprecated or non-existent methods such as `SockAddr::init` instead of `SockAddr::try_init` or `SockAddr::from`, rely on platform-dependent `libc` constants directly rather than `sock_addr.domain()` or `sock_addr.is_ipv4()`, or use unsafe pointers when safe standard library conversions (`From<SocketAddrV4>`, `From<SocketAddrV6>`) are provided.

## How the wrong version fails
Using non-existent `SockAddr::init` causes a compile error (E0599). Unlinked `libc` references fail with unresolved module errors (E0433). Using safe `From` and `domain()` ensures portable compile-time safety and offline verification.
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::SockAddr 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::SockAddr

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:c37aa98932fc9961d50a989bc80c5977971bf71fb9f61422c5cb0cac81343d32","contract":["SockAddr from SocketAddrV4 creates an IPv4 address with Domain::IPV4 and matches as_socket_ipv4","SockAddr from SocketAddrV6 creates an IPv6 address with Domain::IPV6 and matches as_socket_ipv6","SockAddr from generic SocketAddr enum preserves IPv4 and IPv6 representations","SockAddr::unix creates a Unix domain socket address with Domain::UNIX matching as_pathname","SockAddr implements Clone, PartialEq, and Debug formatting"],"goal":"verify socket2::SockAddr in pkg:cargo/socket2@0.6.5","kind":"HOW","packages":["pkg:cargo/socket2@0.6.5"],"schemaVersion":1,"symbols":["socket2::SockAddr"]},"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::SockAddr"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify socket2::SockAddr in pkg:cargo/socket2@0.6.5",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/socket2@0.6.5"
  ],
  "symbols": [
    "socket2::SockAddr"
  ]
}
src/lib.rs
//! Clean-room verification sample for socket2::SockAddr.

pub use socket2::SockAddr;
test/contract.rs
use socket2::{Domain, SockAddr};
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use std::path::Path;

fn main() {
    // 1. SockAddr from SocketAddrV4 creates an IPv4 address with Domain::IPV4 and matches as_socket_ipv4
    let std_v4 = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
    let addr_v4 = SockAddr::from(std_v4);
    assert!(addr_v4.is_ipv4());
    assert!(!addr_v4.is_ipv6());
    #[cfg(unix)]
    assert!(!addr_v4.is_unix());
    assert_eq!(addr_v4.domain(), Domain::IPV4);
    assert!(addr_v4.len() > 0);
    assert_eq!(addr_v4.as_socket(), Some(SocketAddr::V4(std_v4)));
    assert_eq!(addr_v4.as_socket_ipv4(), Some(std_v4));
    assert!(addr_v4.as_socket_ipv6().is_none());

    // 2. SockAddr from SocketAddrV6 creates an IPv6 address with Domain::IPV6 and matches as_socket_ipv6
    let std_v6 = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 9090, 0, 0);
    let addr_v6 = SockAddr::from(std_v6);
    assert!(addr_v6.is_ipv6());
    assert!(!addr_v6.is_ipv4());
    #[cfg(unix)]
    assert!(!addr_v6.is_unix());
    assert_eq!(addr_v6.domain(), Domain::IPV6);
    assert!(addr_v6.len() > 0);
    assert_eq!(addr_v6.as_socket(), Some(SocketAddr::V6(std_v6)));
    assert_eq!(addr_v6.as_socket_ipv6(), Some(std_v6));
    assert!(addr_v4.as_socket_ipv6().is_none());

    // 3. SockAddr from generic SocketAddr enum preserves IPv4 and IPv6 representations
    let from_generic_v4 = SockAddr::from(SocketAddr::V4(std_v4));
    let from_generic_v6 = SockAddr::from(SocketAddr::V6(std_v6));
    assert_eq!(addr_v4, from_generic_v4);
    assert_eq!(addr_v6, from_generic_v6);
    assert_ne!(addr_v4, addr_v6);

    // 4. SockAddr::unix creates a Unix domain socket address with Domain::UNIX matching as_pathname
    #[cfg(unix)]
    {
        let socket_path = "sample.sock";
        let unix_addr = SockAddr::unix(socket_path).expect("valid unix sockaddr");
        assert!(unix_addr.is_unix());
        assert!(!unix_addr.is_ipv4());
        assert!(!unix_addr.is_ipv6());
        assert_eq!(unix_addr.domain(), Domain::UNIX);
        assert!(unix_addr.len() > 0);
        assert!(unix_addr.as_socket().is_none());
        assert_eq!(unix_addr.as_pathname(), Some(Path::new(socket_path)));
    }

    // 5. SockAddr implements Clone, PartialEq, and Debug formatting
    let cloned_v4 = addr_v4.clone();
    assert_eq!(addr_v4, cloned_v4);
    assert_eq!(format!("{:?}", addr_v4), format!("{:?}", cloned_v4));

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

Seeder de origem

anônimo