plcc/src/support.rs
Gregory Bednov c86ad6e5ac new file: compiler.rs
new file:   primitives.rs
	new file:   store.rs
	new file:   support.rs
2025-12-26 15:50:00 +03:00

39 lines
1.1 KiB
Rust

// Platform helpers to ease future no_std portability.
// The crate currently depends on `std`, but concentrating platform-specific
// pieces here makes migration simpler.
#[cfg(feature = "std")]
pub use std::sync::Arc;
#[cfg(feature = "std")]
pub fn run_parallel<L, R, OutL, OutR>(left: L, right: R) -> (OutL, OutR)
where
L: FnOnce() -> OutL + Send + 'static,
R: FnOnce() -> OutR + Send + 'static,
OutL: Send + 'static,
OutR: Send + 'static,
{
let h1 = std::thread::spawn(left);
let h2 = std::thread::spawn(right);
(h1.join().unwrap(), h2.join().unwrap())
}
#[cfg(not(feature = "std"))]
mod no_std_support {
extern crate alloc;
pub use alloc::sync::Arc;
pub fn run_parallel<L, R, OutL, OutR>(left: L, right: R) -> (OutL, OutR)
where
L: FnOnce() -> OutL + Send + 'static,
R: FnOnce() -> OutR + Send + 'static,
OutL: Send + 'static,
OutR: Send + 'static,
{
// No threads available: fall back to sequential execution.
(left(), right())
}
}
#[cfg(not(feature = "std"))]
pub use no_std_support::*;