CodeSampleX

示例

futures-sink 0.3.34

已验证示例 — cargo futures-sink 0.3.34. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: Vec implements Sink allowing items to be sent and buffered via…

sha256:f0f7e9da2bd66976e164934bfdfb4eb77e0098db2fe97605a535ddf0ecfec105

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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/futures-sink@0.3.34
包
创建时间
2026-09-18T21:16:06Z

契约

  1. Vec implements Sink allowing items to be sent and buffered via poll_ready and start_send
  2. VecDeque implements Sink allowing items to be sent and buffered
  3. Box implements Sink forwarding sink operations to the boxed sink
  4. Mutable reference implements Sink forwarding operations to the underlying sink
  5. Custom Sink implementation manages capacity and closed state across poll_ready, start_send, poll_flush, and poll_close

文件

  • 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 = "futures-sink"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"

[[package]]
name = "sample-futures-sink"
version = "1.0.0"
dependencies = [
 "futures-sink",
]
Cargo.toml
[package]
name = "sample-futures-sink"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
futures-sink = "=0.3.34"

[[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/futures-sink@0.3.34
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/futures-sink@0.3.34

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:b5b51a62274142b7c45fc5dcba2922aed1fb6b997db3a757c0d18243044a3471","contract":["Vec implements Sink allowing items to be sent and buffered via poll_ready and start_send","VecDeque implements Sink allowing items to be sent and buffered","Box implements Sink forwarding sink operations to the boxed sink","Mutable reference implements Sink forwarding operations to the underlying sink","Custom Sink implementation manages capacity and closed state across poll_ready, start_send, poll_flush, and poll_close"],"goal":"verify pkg:cargo/futures-sink@0.3.34","kind":"HOW","packages":["pkg:cargo/futures-sink@0.3.34"],"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/futures-sink@0.3.34"],"schemaVersion":1,"subject":"pkg:cargo/futures-sink@0.3.34","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/futures-sink@0.3.34",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/futures-sink@0.3.34"
  ]
}
src/lib.rs
//! Clean-room verification sample for futures-sink.

pub use futures_sink::*;
test/contract.rs
use core::pin::Pin;
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use futures_sink::Sink;
use std::collections::VecDeque;

fn dummy_waker() -> Waker {
    static VTABLE: RawWakerVTable = RawWakerVTable::new(
        |_| RawWaker::new(std::ptr::null(), &VTABLE),
        |_| {},
        |_| {},
        |_| {},
    );
    unsafe { Waker::from_raw(RawWaker::new(std::ptr::null(), &VTABLE)) }
}

struct BoundedChannelSink {
    buffer: Vec<i32>,
    capacity: usize,
    closed: bool,
}

impl BoundedChannelSink {
    fn new(capacity: usize) -> Self {
        Self {
            buffer: Vec::new(),
            capacity,
            closed: false,
        }
    }
}

impl Sink<i32> for BoundedChannelSink {
    type Error = &'static str;

    fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        let this = self.get_mut();
        if this.closed {
            return Poll::Ready(Err("sink is closed"));
        }
        if this.buffer.len() < this.capacity {
            Poll::Ready(Ok(()))
        } else {
            Poll::Pending
        }
    }

    fn start_send(self: Pin<&mut Self>, item: i32) -> Result<(), Self::Error> {
        let this = self.get_mut();
        if this.closed {
            return Err("sink is closed");
        }
        if this.buffer.len() >= this.capacity {
            return Err("sink is full");
        }
        this.buffer.push(item);
        Ok(())
    }

    fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }

    fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        let this = self.get_mut();
        this.closed = true;
        Poll::Ready(Ok(()))
    }
}

fn main() {
    let waker = dummy_waker();
    let mut cx = Context::from_waker(&waker);

    // 1. Vec implements Sink allowing items to be sent and buffered via poll_ready and start_send
    let mut vec_sink = Vec::<i32>::new();
    assert_eq!(Pin::new(&mut vec_sink).poll_ready(&mut cx), Poll::Ready(Ok(())));
    assert!(Pin::new(&mut vec_sink).start_send(10).is_ok());
    assert_eq!(Pin::new(&mut vec_sink).poll_ready(&mut cx), Poll::Ready(Ok(())));
    assert!(Pin::new(&mut vec_sink).start_send(20).is_ok());
    assert_eq!(Pin::new(&mut vec_sink).poll_flush(&mut cx), Poll::Ready(Ok(())));
    assert_eq!(Pin::new(&mut vec_sink).poll_close(&mut cx), Poll::Ready(Ok(())));
    assert_eq!(vec_sink, vec![10, 20]);

    // 2. VecDeque implements Sink allowing items to be sent and buffered
    let mut deque_sink = VecDeque::<&'static str>::new();
    assert_eq!(Pin::new(&mut deque_sink).poll_ready(&mut cx), Poll::Ready(Ok(())));
    assert!(Pin::new(&mut deque_sink).start_send("first").is_ok());
    assert_eq!(Pin::new(&mut deque_sink).poll_ready(&mut cx), Poll::Ready(Ok(())));
    assert!(Pin::new(&mut deque_sink).start_send("second").is_ok());
    assert_eq!(Pin::new(&mut deque_sink).poll_flush(&mut cx), Poll::Ready(Ok(())));
    assert_eq!(deque_sink.pop_front(), Some("first"));
    assert_eq!(deque_sink.pop_front(), Some("second"));
    assert_eq!(deque_sink.pop_front(), None);

    // 3. Box implements Sink forwarding sink operations to the boxed sink
    let mut boxed: Box<dyn Sink<i32, Error = core::convert::Infallible> + Unpin> = Box::new(Vec::new());
    assert_eq!(Pin::new(&mut boxed).poll_ready(&mut cx), Poll::Ready(Ok(())));
    assert!(Pin::new(&mut boxed).start_send(99).is_ok());
    assert_eq!(Pin::new(&mut boxed).poll_flush(&mut cx), Poll::Ready(Ok(())));
    assert_eq!(Pin::new(&mut boxed).poll_close(&mut cx), Poll::Ready(Ok(())));

    // 4. Mutable reference implements Sink forwarding operations to the underlying sink
    let mut target_vec = Vec::<i32>::new();
    {
        let mut ref_sink = &mut target_vec;
        assert_eq!(Pin::new(&mut ref_sink).poll_ready(&mut cx), Poll::Ready(Ok(())));
        assert!(Pin::new(&mut ref_sink).start_send(123).is_ok());
        assert_eq!(Pin::new(&mut ref_sink).poll_flush(&mut cx), Poll::Ready(Ok(())));
    }
    assert_eq!(target_vec, vec![123]);

    // 5. Custom Sink implementation manages capacity and closed state across poll_ready, start_send, poll_flush, and poll_close
    let mut custom_sink = BoundedChannelSink::new(2);
    assert_eq!(Pin::new(&mut custom_sink).poll_ready(&mut cx), Poll::Ready(Ok(())));
    assert_eq!(Pin::new(&mut custom_sink).start_send(1), Ok(()));
    assert_eq!(Pin::new(&mut custom_sink).poll_ready(&mut cx), Poll::Ready(Ok(())));
    assert_eq!(Pin::new(&mut custom_sink).start_send(2), Ok(()));
    // Sink is now full: poll_ready returns Pending and start_send returns Err
    assert_eq!(Pin::new(&mut custom_sink).poll_ready(&mut cx), Poll::Pending);
    assert_eq!(Pin::new(&mut custom_sink).start_send(3), Err("sink is full"));
    // Flush and close
    assert_eq!(Pin::new(&mut custom_sink).poll_flush(&mut cx), Poll::Ready(Ok(())));
    assert_eq!(Pin::new(&mut custom_sink).poll_close(&mut cx), Poll::Ready(Ok(())));
    // After closing: poll_ready and start_send return closed error
    assert_eq!(Pin::new(&mut custom_sink).poll_ready(&mut cx), Poll::Ready(Err("sink is closed")));
    assert_eq!(Pin::new(&mut custom_sink).start_send(4), Err("sink is closed"));
    assert_eq!(custom_sink.buffer, vec![1, 2]);

    println!("All futures-sink contract assertions passed successfully.");
}

原始种子者

匿名