CodeSampleX

샘플

mio 1.2.2

검증된 샘플 — cargo mio 1.2.2. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Poll and Events initialize with capacity and handle empty poll timeout

sha256:513ec37fc0e29546b1f232d68b1904178b0f9699be29e2822ece8df28af1a22d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux · alpine · musl x64 cargo

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:cargo/mio@1.2.2
패키지
생성일
2026-09-18T11:59:46Z

컨트랙트

  1. Poll and Events initialize with capacity and handle empty poll timeout
  2. Interest combines readable and writable readiness states
  3. Waker registers with Poll registry and wakes poll waiting on events
  4. TcpListener and TcpStream bind, register, and transmit bytes across non-blocking connection

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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 = "log"
version = "0.4.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"

[[package]]
name = "mio"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427"
dependencies = [
 "libc",
 "log",
 "wasi",
 "windows-sys",
]

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

[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"

[[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-mio"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
mio = { version = "=1.2.2", features = ["os-poll", "net"] }

[[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/mio@1.2.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/mio@1.2.2

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:d62cebf97ea061788e8b51d37a8167ff9d622461beb505f4fef53fcdac9fbeee","contract":["Poll and Events initialize with capacity and handle empty poll timeout","Interest combines readable and writable readiness states","Waker registers with Poll registry and wakes poll waiting on events","TcpListener and TcpStream bind, register, and transmit bytes across non-blocking connection"],"goal":"verify pkg:cargo/mio@1.2.2","kind":"HOW","packages":["pkg:cargo/mio@1.2.2"],"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/mio@1.2.2"],"schemaVersion":1,"subject":"pkg:cargo/mio@1.2.2","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/mio@1.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/mio@1.2.2"
  ]
}
src/lib.rs
//! Clean-room verification sample for mio.

pub use mio::*;
test/contract.rs
use mio::net::{TcpListener, TcpStream};
use mio::{Events, Interest, Poll, Token, Waker};
use std::io::{Read, Write};
use std::time::Duration;

fn main() {
    // 1. Poll and Events initialize with capacity and handle empty poll timeout
    let mut poll = Poll::new().expect("Failed to create Poll instance");
    let mut events = Events::with_capacity(64);
    assert!(events.is_empty());
    assert_eq!(events.capacity(), 64);

    poll.poll(&mut events, Some(Duration::from_millis(10)))
        .expect("Poll timed out or errored");
    assert!(events.is_empty());

    // 2. Interest combines readable and writable readiness states
    let read = Interest::READABLE;
    let write = Interest::WRITABLE;
    let combined = read.add(write);
    assert!(combined.is_readable());
    assert!(combined.is_writable());
    assert!(read.is_readable());
    assert!(!read.is_writable());
    assert!(!write.is_readable());
    assert!(write.is_writable());

    // 3. Waker registers with Poll registry and wakes poll waiting on events
    const WAKER_TOKEN: Token = Token(10);
    let waker = Waker::new(poll.registry(), WAKER_TOKEN).expect("Failed to create Waker");
    waker.wake().expect("Failed to wake Poll");

    poll.poll(&mut events, Some(Duration::from_millis(100)))
        .expect("Failed to poll for waker event");
    assert!(!events.is_empty());

    let mut waker_found = false;
    for event in events.iter() {
        if event.token() == WAKER_TOKEN && event.is_readable() {
            waker_found = true;
        }
    }
    assert!(waker_found, "Waker event was not observed");

    // 4. TcpListener and TcpStream bind, register, and transmit bytes across non-blocking connection
    const LISTENER_TOKEN: Token = Token(1);
    const CLIENT_TOKEN: Token = Token(2);
    const SERVER_STREAM_TOKEN: Token = Token(3);

    let mut listener = TcpListener::bind("127.0.0.1:0".parse().unwrap())
        .expect("Failed to bind TcpListener to loopback");
    let addr = listener.local_addr().expect("Failed to get local address");

    poll.registry()
        .register(&mut listener, LISTENER_TOKEN, Interest::READABLE)
        .expect("Failed to register TcpListener");

    let mut client = TcpStream::connect(addr).expect("Failed to connect TcpStream");
    poll.registry()
        .register(&mut client, CLIENT_TOKEN, Interest::WRITABLE | Interest::READABLE)
        .expect("Failed to register client TcpStream");

    let mut server_stream = None;
    let mut client_writable = false;

    for _ in 0..20 {
        events.clear();
        poll.poll(&mut events, Some(Duration::from_millis(100)))
            .expect("Failed to poll connection events");

        for event in events.iter() {
            if event.token() == LISTENER_TOKEN && event.is_readable() {
                if let Ok((stream, _)) = listener.accept() {
                    server_stream = Some(stream);
                }
            }
            if event.token() == CLIENT_TOKEN && event.is_writable() {
                client_writable = true;
            }
        }

        if server_stream.is_some() && client_writable {
            break;
        }
    }

    assert!(server_stream.is_some(), "Listener never accepted connection");
    let mut server = server_stream.unwrap();

    poll.registry()
        .register(&mut server, SERVER_STREAM_TOKEN, Interest::READABLE)
        .expect("Failed to register server stream");

    // Send data from client to server
    let payload = b"mio ping test";
    let n = client.write(payload).expect("Client failed to write bytes");
    assert_eq!(n, payload.len());

    let mut received = Vec::new();
    let mut buf = [0u8; 64];

    for _ in 0..20 {
        events.clear();
        poll.poll(&mut events, Some(Duration::from_millis(100)))
            .expect("Failed to poll read events");

        for event in events.iter() {
            if event.token() == SERVER_STREAM_TOKEN && event.is_readable() {
                match server.read(&mut buf) {
                    Ok(read_bytes) if read_bytes > 0 => {
                        received.extend_from_slice(&buf[..read_bytes]);
                    }
                    _ => {}
                }
            }
        }

        if received.len() >= payload.len() {
            break;
        }
    }

    assert_eq!(&received[..], payload, "Transmitted payload does not match received");

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

오리진 시더

익명