nd_async_rusqlite/sync_wrapper.rs
1/// Inspired by https://internals.rust-lang.org/t/what-shall-sync-mean-across-an-await/12020/2.
2#[repr(transparent)]
3#[derive(Debug)]
4pub struct SyncWrapper<T>(T);
5
6impl<T> SyncWrapper<T> {
7 /// Create a new [`SyncWrapper`] over an item.
8 pub(crate) fn new(item: T) -> Self {
9 Self(item)
10 }
11
12 /// Consume this object to access the inner item.
13 pub fn into_inner(self) -> T {
14 self.0
15 }
16}
17
18// Safety:
19// * This is safe as this type is useless without an immutable reference.
20unsafe impl<T> Sync for SyncWrapper<T> where T: Send {}