diff options
Diffstat (limited to 'crates/utils')
-rw-r--r-- | crates/utils/src/lib.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 3649666..6e26317 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -1,7 +1,11 @@ //! Common utilities. #![no_std] -use core::{fmt, mem::size_of}; +use core::{ + fmt, + mem::size_of, + ops::{Deref, DerefMut}, +}; /// Creates an ad-hoc `Debug` instance. pub fn debug(f: impl Fn(&mut fmt::Formatter) -> fmt::Result) -> impl fmt::Debug { @@ -66,6 +70,25 @@ macro_rules! dbg { }; } +/// A wrapper type that promises that its contents are Send. +pub struct BelieveMeSend<T>(pub T); + +impl<T> Deref for BelieveMeSend<T> { + type Target = T; + + fn deref(&self) -> &T { + &self.0 + } +} + +impl<T> DerefMut for BelieveMeSend<T> { + fn deref_mut(&mut self) -> &mut T { + &mut self.0 + } +} + +unsafe impl<T> Send for BelieveMeSend<T> {} + /// A trait for types that can be converted to from big-endian or little-endian byte slices. pub trait FromEndianBytes { /// Converts from a big-endian byte slice. |