russh-util-0.52.0/.cargo_vcs_info.json0000644000000001730000000000100132400ustar { "git": { "sha1": "3d09c20c52a542ffa327723d3a44cb1edd9b0ca4", "dirty": true }, "path_in_vcs": "russh-util" }russh-util-0.52.0/Cargo.toml0000644000000026040000000000100112370ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.75" name = "russh-util" version = "0.52.0" build = false autobins = false autoexamples = false autotests = false autobenches = false description = "Runtime abstraction utilities for russh." homepage = "https://github.com/warp-tech/russh" documentation = "https://docs.rs/russh-util" readme = false license = "Apache-2.0" repository = "https://github.com/warp-tech/russh" [lib] name = "russh_util" path = "src/lib.rs" [dependencies.tokio] version = "1.17.0" features = [ "sync", "macros", ] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] version = "1.17.0" features = [ "io-util", "rt-multi-thread", "rt", ] [target.'cfg(target_arch = "wasm32")'.dependencies.chrono] version = "0.4.38" [target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen] version = "0.2" [target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen-futures] version = "0.4.43" russh-util-0.52.0/Cargo.toml.orig000064400000000000000000000012071046102023000147160ustar 00000000000000[package] name = "russh-util" version = "0.52.0" edition = "2021" rust-version = "1.75" description = "Runtime abstraction utilities for russh." documentation = "https://docs.rs/russh-util" homepage = "https://github.com/warp-tech/russh" license = "Apache-2.0" repository = "https://github.com/warp-tech/russh" [dependencies] tokio = { workspace = true, features = ["sync", "macros"] } [target.'cfg(target_arch = "wasm32")'.dependencies] chrono = "0.4.38" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4.43" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { workspace = true, features = ["io-util", "rt-multi-thread", "rt"] } russh-util-0.52.0/src/lib.rs000064400000000000000000000000371046102023000137320ustar 00000000000000pub mod runtime; pub mod time; russh-util-0.52.0/src/runtime.rs000064400000000000000000000025701046102023000146530ustar 00000000000000use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; #[derive(Debug)] pub struct JoinError; impl std::fmt::Display for JoinError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "JoinError") } } impl std::error::Error for JoinError {} pub struct JoinHandle where T: Send, { handle: tokio::sync::oneshot::Receiver, } #[cfg(target_arch = "wasm32")] macro_rules! spawn_impl { ($fn:expr) => { wasm_bindgen_futures::spawn_local($fn) }; } #[cfg(not(target_arch = "wasm32"))] macro_rules! spawn_impl { ($fn:expr) => { tokio::spawn($fn) }; } pub fn spawn(future: F) -> JoinHandle where F: Future + 'static + Send, T: Send + 'static, { let (sender, receiver) = tokio::sync::oneshot::channel(); spawn_impl!(async { let result = future.await; let _ = sender.send(result); }); JoinHandle { handle: receiver } } impl Future for JoinHandle where T: Send, { type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match Pin::new(&mut self.handle).poll(cx) { Poll::Ready(Ok(val)) => Poll::Ready(Ok(val)), Poll::Ready(Err(_)) => Poll::Ready(Err(JoinError)), Poll::Pending => Poll::Pending, } } } russh-util-0.52.0/src/time.rs000064400000000000000000000011631046102023000141230ustar 00000000000000#[cfg(not(target_arch = "wasm32"))] pub use std::time::Instant; #[cfg(target_arch = "wasm32")] pub use wasm::Instant; #[cfg(target_arch = "wasm32")] mod wasm { #[derive(Debug, Clone, Copy)] pub struct Instant { inner: chrono::DateTime, } impl Instant { pub fn now() -> Self { Instant { inner: chrono::Utc::now(), } } pub fn duration_since(&self, earlier: Instant) -> std::time::Duration { (self.inner - earlier.inner) .to_std() .expect("Duration is negative") } } }