From 7879ac01b24eb9723ec0a814adaee1fc9c52610a Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 18 Jun 2026 04:40:25 +0800 Subject: feat(rola-cli): implement bucket creation and CLI entry point Add bucket creation logic with pre-checks, localized error handling, and a basic CLI entry point using the mingling framework. Introduce a placeholder protocol for bucket transfer testing. --- rola-cli/src/tokio_wrapper.rs | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 rola-cli/src/tokio_wrapper.rs (limited to 'rola-cli/src/tokio_wrapper.rs') diff --git a/rola-cli/src/tokio_wrapper.rs b/rola-cli/src/tokio_wrapper.rs new file mode 100644 index 0000000..8293355 --- /dev/null +++ b/rola-cli/src/tokio_wrapper.rs @@ -0,0 +1,48 @@ +use std::future::Future; + +/// Runs an async function to completion by creating a Tokio runtime +/// and blocking on the future within it. +/// +/// # Example +/// +/// ``` +/// use tokio_wrapper::tokio_run; +/// +/// let result = tokio_run(async { +/// // your async code here +/// 42 +/// }); +/// println!("Result: {}", result); +/// ``` +pub fn tokio_run(future: F) -> T +where + F: Future, +{ + // Create a new Tokio runtime and block on the future + let rt = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime"); + rt.block_on(future) +} + +/// A macro that wraps an async expression with `tokio_run`. +/// +/// Equivalent to: +/// ```ignore +/// tokio_run(async move { ... }) +/// ``` +/// +/// # Example +/// +/// ``` +/// use tokio_wrapper::tkr; +/// +/// // Instead of: +/// // tokio_run(async move { some_async_fn().await }) +/// // Use: +/// let result = tkr! { some_async_fn().await }; +/// ``` +#[macro_export] +macro_rules! tkr { + ($($expr:tt)*) => { + $crate::tokio_wrapper::tokio_run(async move { $($expr)* }) + }; +} -- cgit