feat(rust): add rust sdk (#5909)
* upload client * add gh workflow * refactor build script * remove dbg! * fix async * remove unused * update dev.nu * update CI * fix ci * fixin tests * fixes + tests
This commit is contained in:
48
rust-client/src/maybe_future.rs
Normal file
48
rust-client/src/maybe_future.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
// #[cfg(feature = "async")]
|
||||
// use futures::future::BoxFuture;
|
||||
|
||||
/// A conditional type that represents either:
|
||||
/// - A boxed future (async mode)
|
||||
/// - A direct value (sync mode)
|
||||
pub mod maybe_future {
|
||||
#[cfg(feature = "async")]
|
||||
pub type MaybeFuture<'a, T> = futures::future::BoxFuture<'a, T>;
|
||||
#[cfg(not(feature = "async"))]
|
||||
pub type MaybeFuture<'a, T> = T;
|
||||
}
|
||||
|
||||
/// Bridges between async and sync execution contexts
|
||||
///
|
||||
/// Behavior depends on compilation:
|
||||
/// - With `async` feature: Returns a boxed future
|
||||
/// - Without `async` feature: Blocks on the global runtime
|
||||
#[macro_export]
|
||||
macro_rules! ret {
|
||||
($ex:expr) => {
|
||||
#[cfg(feature = "async")]
|
||||
return async move { $ex.await }.boxed();
|
||||
|
||||
#[cfg(not(feature = "async"))]
|
||||
return crate::maybe_future::RUNTIME.block_on($ex);
|
||||
};
|
||||
}
|
||||
|
||||
/// The global Tokio runtime instance used in sync mode
|
||||
///
|
||||
/// Initialized lazily with:
|
||||
/// - I/O capabilities
|
||||
/// - Time utilities
|
||||
/// - Current-thread executor
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If Tokio fails to initialize the runtime
|
||||
#[cfg(not(feature = "async"))]
|
||||
pub(crate) static RUNTIME: once_cell::sync::Lazy<tokio::runtime::Runtime> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_io()
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap()
|
||||
});
|
||||
Reference in New Issue
Block a user