Debian Codegraph @

third_party/rust/tokio/src/util/sync_wrapper.rs

raw
1 //! This module contains a type that can make `Send + !Sync` types `Sync` by
2 //! disallowing all immutable access to the value.
3 //!
4 //! A similar primitive is provided in the `sync_wrapper` crate.
5
6 pub(crate) struct SyncWrapper<T> {
7 value: T,
8 }
9
10 // safety: The SyncWrapper being send allows you to send the inner value across
11 // thread boundaries.
12 unsafe impl<T: Send> Send for SyncWrapper<T> {}
13
14 // safety: An immutable reference to a SyncWrapper is useless, so moving such an
15 // immutable reference across threads is safe.
16 unsafe impl<T> Sync for SyncWrapper<T> {}
17
18 impl<T> SyncWrapper<T> {
19 pub(crate) fn new(value: T) -> Self {
20 Self { value }
21 }
22
23 pub(crate) fn into_inner(self) -> T {
24 self.value
25 }
26 }