CodeSampleX

Ejemplo

futures-macro 0.3.34

Muestra verificada para cargo futures-macro 0.3.34. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó: futures_macro::join_internal! polls…

sha256:2cd625e9316fc5bc80dfb484e16e6242a917c1dc92f6df19af5d7d94e5e76fd7

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 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-10-31

Caso

HOW
Objetivo
verify pkg:cargo/futures-macro@0.3.34
Paquetes
Creado
2026-10-31T15:29:50Z

Contrato

  1. futures_macro::join_internal! polls multiple futures to completion and returns their tuple of outputs
  2. futures_macro::try_join_internal! returns Ok tuple when all futures succeed and short-circuits with Err on failure
  3. futures_macro::select_biased_internal! and futures_macro::select_internal! poll fused futures and evaluate the ready or default branch
  4. futures_macro::stream_select_internal! merges multiple streams into a single Stream yielding all items

Archivos

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • src/main.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 = "futures-macro"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "sample"
version = "0.1.0"
dependencies = [
 "futures-macro",
]

[[package]]
name = "syn"
version = "3.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
Cargo.toml
[package]
name = "sample"
version = "0.1.0"
edition = "2021"

[dependencies]
futures-macro = "=0.3.34"

[[test]]
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-macro@0.3.34
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/futures-macro@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:f48ee81fc12fd50eb5b1fb39532c42a64950126471be90f87e4d86d645014856","contract":["futures_macro::join_internal! polls multiple futures to completion and returns their tuple of outputs","futures_macro::try_join_internal! returns Ok tuple when all futures succeed and short-circuits with Err on failure","futures_macro::select_biased_internal! and futures_macro::select_internal! poll fused futures and evaluate the ready or default branch","futures_macro::stream_select_internal! merges multiple streams into a single Stream yielding all items"],"goal":"verify pkg:cargo/futures-macro@0.3.34","kind":"HOW","packages":["pkg:cargo/futures-macro@0.3.34"],"schemaVersion":1},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/futures-macro@0.3.34"],"schemaVersion":1,"subject":"pkg:cargo/futures-macro@0.3.34","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/futures-macro@0.3.34",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/futures-macro@0.3.34"
  ]
}
src/lib.rs
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};

pub mod __futures_crate {
    pub use std::option::Option::{self, None, Some};
    pub use std::pin::Pin;
    pub use std::result::Result::{Err, Ok};

    pub mod task {
        pub use std::task::{Context, Poll};
        use std::task::{RawWaker, RawWakerVTable, Waker};

        pub fn noop_waker_ref() -> &'static Waker {
            static VTABLE: RawWakerVTable = RawWakerVTable::new(
                |_| RawWaker::new(std::ptr::null(), &VTABLE),
                |_| {},
                |_| {},
                |_| {},
            );
            static WAKER: std::sync::OnceLock<Waker> = std::sync::OnceLock::new();
            WAKER.get_or_init(|| unsafe { Waker::from_raw(RawWaker::new(std::ptr::null(), &VTABLE)) })
        }
    }

    pub mod future {
        pub use std::future::{poll_fn, Future};
        use std::pin::Pin;
        use std::task::{Context, Poll};

        pub enum MaybeDone<F: Future> {
            Future(F),
            Done(F::Output),
            Gone,
        }

        pub fn maybe_done<F: Future>(future: F) -> MaybeDone<F> {
            MaybeDone::Future(future)
        }

        impl<F: Future> MaybeDone<F> {
            pub fn take_output(self: Pin<&mut Self>) -> Option<F::Output> {
                unsafe {
                    let this = self.get_unchecked_mut();
                    match this {
                        MaybeDone::Done(_) => {
                            if let MaybeDone::Done(output) =
                                std::mem::replace(this, MaybeDone::Gone)
                            {
                                Some(output)
                            } else {
                                unreachable!()
                            }
                        }
                        _ => None,
                    }
                }
            }

            pub fn output_mut(self: Pin<&mut Self>) -> Option<&mut F::Output> {
                unsafe {
                    match self.get_unchecked_mut() {
                        MaybeDone::Done(output) => Some(output),
                        _ => None,
                    }
                }
            }
        }

        impl<F: Future> Future for MaybeDone<F> {
            type Output = ();

            fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
                unsafe {
                    match self.as_mut().get_unchecked_mut() {
                        MaybeDone::Future(f) => match Pin::new_unchecked(f).poll(cx) {
                            Poll::Ready(output) => {
                                self.set(MaybeDone::Done(output));
                                Poll::Ready(())
                            }
                            Poll::Pending => Poll::Pending,
                        },
                        MaybeDone::Done(_) => Poll::Ready(()),
                        MaybeDone::Gone => panic!("MaybeDone polled after output taken"),
                    }
                }
            }
        }

        pub trait FusedFuture: Future {
            fn is_terminated(&self) -> bool;
        }

        impl<F: FusedFuture + ?Sized> FusedFuture for Pin<&mut F> {
            fn is_terminated(&self) -> bool {
                <F as FusedFuture>::is_terminated(&**self)
            }
        }

        pub trait FutureExt: Future {
            fn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output>
            where
                Self: Unpin,
            {
                Pin::new(self).poll(cx)
            }
        }

        impl<F: Future + ?Sized> FutureExt for F {}
    }

    pub mod async_await {
        pub fn assert_fused_future<F: super::future::FusedFuture>(_: &F) {}
        pub fn assert_unpin<F: Unpin>(_: &F) {}
        pub fn shuffle<T>(_: &mut [T]) {}
    }

    pub mod stream {
        use std::pin::Pin;
        use std::task::{Context, Poll};

        pub trait Stream {
            type Item;
            fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
            fn size_hint(&self) -> (usize, Option<usize>) {
                (0, None)
            }
        }

        impl<S: Stream + Unpin + ?Sized> Stream for &mut S {
            type Item = S::Item;
            fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
                S::poll_next(Pin::new(&mut **self), cx)
            }
            fn size_hint(&self) -> (usize, Option<usize>) {
                (**self).size_hint()
            }
        }
    }
}

pub fn block_on<F: Future>(mut fut: F) -> F::Output {
    static VTABLE: RawWakerVTable = RawWakerVTable::new(
        |_| RawWaker::new(std::ptr::null(), &VTABLE),
        |_| {},
        |_| {},
        |_| {},
    );
    let waker = unsafe { Waker::from_raw(RawWaker::new(std::ptr::null(), &VTABLE)) };
    let mut cx = Context::from_waker(&waker);
    let mut fut = unsafe { Pin::new_unchecked(&mut fut) };
    loop {
        if let Poll::Ready(val) = fut.as_mut().poll(&mut cx) {
            return val;
        }
    }
}

pub struct YieldOnce<T>(Option<T>, bool);

impl<T> YieldOnce<T> {
    pub fn new(val: T) -> Self {
        Self(Some(val), false)
    }
}

impl<T: Unpin> Future for YieldOnce<T> {
    type Output = T;
    fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
        if !self.1 {
            self.1 = true;
            Poll::Pending
        } else {
            Poll::Ready(self.0.take().unwrap())
        }
    }
}

impl<T: Unpin> __futures_crate::future::FusedFuture for YieldOnce<T> {
    fn is_terminated(&self) -> bool {
        self.0.is_none()
    }
}

pub struct SliceStream<T>(pub Vec<T>);

impl<T: Unpin> __futures_crate::stream::Stream for SliceStream<T> {
    type Item = T;
    fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<T>> {
        if self.0.is_empty() {
            Poll::Ready(None)
        } else {
            Poll::Ready(Some(self.0.remove(0)))
        }
    }
    fn size_hint(&self) -> (usize, Option<usize>) {
        let len = self.0.len();
        (len, Some(len))
    }
}

pub fn run_contract() {
    // 1. join_internal! polls multiple futures to completion and returns tuple of outputs
    let joined = block_on(async {
        futures_macro::join_internal!(YieldOnce::new(10), async { 20 })
    });
    assert_eq!(joined, (10, 20));

    // 2. try_join_internal! returns Ok tuple when all succeed, or short-circuits with Err
    let try_ok: Result<(i32, i32), &str> = block_on(async {
        futures_macro::try_join_internal!(
            YieldOnce::new(Ok::<i32, &str>(3)),
            async { Ok::<i32, &str>(4) }
        )
    });
    assert_eq!(try_ok, Ok((3, 4)));

    let try_err: Result<(i32, i32), &str> = block_on(async {
        futures_macro::try_join_internal!(
            YieldOnce::new(Ok::<i32, &str>(3)),
            async { Err::<i32, &str>("boom") }
        )
    });
    assert_eq!(try_err, Err("boom"));

    // 3. select_biased_internal! and select_internal! poll fused futures in priority/select order
    let selected = block_on(async {
        let mut a = YieldOnce::new(100);
        let mut b = YieldOnce::new(200);
        // Poll `b` once so it becomes Ready on next poll while `a` is Pending on first poll
        let waker = __futures_crate::task::noop_waker_ref();
        let mut cx = Context::from_waker(waker);
        assert_eq!(Pin::new(&mut b).poll(&mut cx), Poll::Pending);

        futures_macro::select_biased_internal! {
            va = a => va,
            vb = b => vb,
        }
    });
    assert_eq!(selected, 200);

    let default_selected = block_on(async {
        let mut pending = YieldOnce::new(1);
        futures_macro::select_internal! {
            v = pending => v,
            default => 42,
        }
    });
    assert_eq!(default_selected, 42);

    // 4. stream_select_internal! merges multiple streams into a single Stream
    let mut merged = futures_macro::stream_select_internal!(
        SliceStream(vec![1, 3]),
        SliceStream(vec![2, 4])
    );
    let mut items = Vec::new();
    let waker = __futures_crate::task::noop_waker_ref();
    let mut cx = Context::from_waker(waker);
    while let Poll::Ready(Some(item)) =
        __futures_crate::stream::Stream::poll_next(Pin::new(&mut merged), &mut cx)
    {
        items.push(item);
    }
    items.sort();
    assert_eq!(items, vec![1, 2, 3, 4]);
}
src/main.rs
fn main() {
    sample::run_contract();
}
test/contract.rs
#[test]
fn contract() {
    sample::run_contract();
}

Seeder de origen

anónimo