use core::ops::{Deref, DerefMut}; #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone, Copy)] pub struct Send(pub T); unsafe impl core::marker::Send for Send {} impl Deref for Send { type Target = T; fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for Send { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl Send { pub unsafe fn new(value: T) -> Self { Self(value) } pub fn into_inner(self) -> T { self.0 } } /// returns the number of available hardware threads, or 1 if it cannot be determined. #[cfg(feature = "std")] pub fn available_parallelism() -> usize { std::thread::available_parallelism() .map(|n| n.get()) .unwrap_or(1) } #[cfg(feature = "std")] pub fn unwrap_or_panic(result: std::thread::Result) -> T { match result { Ok(value) => value, Err(payload) => std::panic::resume_unwind(payload), } } #[deprecated( since = "0.1.0", note = "use `can_transmute` from `mem` module instead" )] pub use super::mem::can_transmute; /// True if `c` is considered a whitespace according to Rust language definition. /// See [Rust language reference](https://doc.rust-lang.org/reference/whitespace.html) /// for definitions of these classes. pub fn is_whitespace(c: char) -> bool { // This is Pattern_White_Space. // // Note that this set is stable (ie, it doesn't change with different // Unicode versions), so it's ok to just hard-code the values. matches!( c, // Usual ASCII suspects '\u{0009}' // \t | '\u{000A}' // \n | '\u{000B}' // vertical tab | '\u{000C}' // form feed | '\u{000D}' // \r | '\u{0020}' // space // NEXT LINE from latin1 | '\u{0085}' // Bidi markers | '\u{200E}' // LEFT-TO-RIGHT MARK | '\u{200F}' // RIGHT-TO-LEFT MARK // Dedicated whitespace characters from Unicode | '\u{2028}' // LINE SEPARATOR | '\u{2029}' // PARAGRAPH SEPARATOR ) }