CodeSampleX

示例

tokio-macros 2.7.2: tokio_macros::main, tokio_macros::test

已验证示例 — cargo tokio-macros 2.7.2: tokio_macros::main, tokio_macros::test. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过.

sha256:8a849c6363e40421a5a80ddb99ab2e4fabeed26f4082ebc061ebd2ac3da82656

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 rust linux x64 rust rust 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-16

案例

HOW
目标
verify pkg:cargo/tokio-macros@2.7.2
包
符号
  • tokio_macros::main
  • tokio_macros::test
环境
rust
创建时间
2026-09-16T22:16:19Z

契约

  1. tokio_macros::main transforms async function into synchronous entry point running on current_thread flavor
  2. tokio_macros::main supports multi_thread flavor and worker_threads parameter
  3. tokio_macros::main accepts crate parameter to redirect runtime path
  4. tokio_macros::test generates executable async test runner with current_thread and multi_thread flavors

文件

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

[[package]]
name = "tokio-macros"
version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "tokio_macros_sample"
version = "0.1.0"
dependencies = [
 "tokio-macros",
]

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

[dependencies]
tokio-macros = "=2.7.2"

[lib]
name = "tokio_macros_sample"
path = "src/lib.rs"

[[bin]]
name = "tokio_macros_sample"
path = "src/main.rs"

[[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/tokio-macros@2.7.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/tokio-macros@2.7.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:9f1bebea96ff7ac40557abc6559b738843d617ee13cc7a1fd4c413f41ac74999","contract":["tokio_macros::main transforms async function into synchronous entry point running on current_thread flavor","tokio_macros::main supports multi_thread flavor and worker_threads parameter","tokio_macros::main accepts crate parameter to redirect runtime path","tokio_macros::test generates executable async test runner with current_thread and multi_thread flavors"],"goal":"verify pkg:cargo/tokio-macros@2.7.2","kind":"HOW","packages":["pkg:cargo/tokio-macros@2.7.2"],"schemaVersion":1,"symbols":["tokio_macros::main","tokio_macros::test"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/tokio-macros@2.7.2"],"schemaVersion":1,"subject":"pkg:cargo/tokio-macros@2.7.2","symbols":["tokio_macros::main","tokio_macros::test"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/tokio-macros@2.7.2",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/tokio-macros@2.7.2"
  ],
  "symbols": [
    "tokio_macros::main",
    "tokio_macros::test"
  ]
}
src/lib.rs
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};

pub use tokio_macros::{main, test};

#[macro_export]
macro_rules! pin {
    ($($x:ident),*) => { $(
        let mut $x = $x;
        #[allow(unused_mut)]
        let mut $x = unsafe {
            ::core::pin::Pin::new_unchecked(&mut $x)
        };
    )* }
}

pub mod runtime {
    use super::*;

    fn dummy_raw_waker() -> RawWaker {
        fn noop(_: *const ()) {}
        fn clone(p: *const ()) -> RawWaker {
            RawWaker::new(p, &VTABLE)
        }
        static VTABLE: RawWakerVTable = RawWakerVTable::new(clone, noop, noop, noop);
        RawWaker::new(std::ptr::null(), &VTABLE)
    }

    #[derive(Debug, Default)]
    pub struct Runtime {
        pub flavor: &'static str,
        pub worker_threads: Option<usize>,
    }

    impl Runtime {
        pub fn block_on<F: Future>(&self, mut future: F) -> F::Output {
            let waker = unsafe { Waker::from_raw(dummy_raw_waker()) };
            let mut cx = Context::from_waker(&waker);
            let mut pinned = unsafe { Pin::new_unchecked(&mut future) };
            match pinned.as_mut().poll(&mut cx) {
                Poll::Ready(res) => res,
                Poll::Pending => panic!("Future did not resolve immediately in contract test"),
            }
        }
    }

    #[derive(Debug, Default)]
    pub struct Builder {
        pub flavor: &'static str,
        pub worker_threads: Option<usize>,
        pub start_paused: bool,
        pub name: Option<String>,
    }

    impl Builder {
        pub fn new_current_thread() -> Self {
            Self {
                flavor: "current_thread",
                ..Default::default()
            }
        }

        pub fn new_multi_thread() -> Self {
            Self {
                flavor: "multi_thread",
                ..Default::default()
            }
        }

        pub fn worker_threads(&mut self, val: usize) -> &mut Self {
            self.worker_threads = Some(val);
            self
        }

        pub fn start_paused(&mut self, val: bool) -> &mut Self {
            self.start_paused = val;
            self
        }

        pub fn name(&mut self, val: &str) -> &mut Self {
            self.name = Some(val.to_string());
            self
        }

        pub fn enable_all(&mut self) -> &mut Self {
            self
        }

        pub fn build(&mut self) -> Result<Runtime, &'static str> {
            Ok(Runtime {
                flavor: self.flavor,
                worker_threads: self.worker_threads,
            })
        }
    }
}
src/main.rs
use tokio_macros_sample as tokio;

#[tokio_macros::main(flavor = "current_thread")]
async fn main() {
    println!("tokio_macros::main entry point executed");
}
test/contract.rs
use tokio_macros_sample as tokio;

#[tokio_macros::main(flavor = "current_thread")]
async fn sample_current_thread_fn() -> i32 {
    42
}

#[tokio_macros::main(flavor = "multi_thread", worker_threads = 4)]
async fn sample_multi_thread_fn() -> &'static str {
    "multi_thread_ok"
}

#[tokio_macros::main(flavor = "current_thread", crate = "tokio_macros_sample")]
async fn sample_custom_crate_fn() -> bool {
    true
}

#[tokio_macros::test]
async fn test_macro_with_default_crate() {
    let result = sample_current_thread_fn();
    assert_eq!(result, 42);
}

#[tokio_macros::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_macro_multi_thread() {
    let result = sample_multi_thread_fn();
    assert_eq!(result, "multi_thread_ok");
}

#[tokio_macros::test(flavor = "current_thread", crate = "tokio_macros_sample")]
async fn test_macro_with_custom_crate_option() {
    let result = sample_custom_crate_fn();
    assert!(result);
}

原始种子者

匿名