1
+ // Copyright 2017 Thomas Keh.
2
+ // Copyright 2024 compio-rs
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7
+ // option. This file may not be copied, modified, or distributed
8
+ // except according to those terms.
9
+
1
10
use std:: {
2
11
cell:: Cell ,
3
12
mem:: { self , ManuallyDrop } ,
@@ -17,6 +26,7 @@ pub struct SendWrapper<T> {
17
26
impl < T > SendWrapper < T > {
18
27
/// Create a `SendWrapper<T>` wrapper around a value of type `T`.
19
28
/// The wrapper takes ownership of the value.
29
+ #[ inline]
20
30
pub fn new ( data : T ) -> SendWrapper < T > {
21
31
SendWrapper {
22
32
data : ManuallyDrop :: new ( data) ,
@@ -26,6 +36,7 @@ impl<T> SendWrapper<T> {
26
36
27
37
/// Returns `true` if the value can be safely accessed from within the
28
38
/// current thread.
39
+ #[ inline]
29
40
pub fn valid ( & self ) -> bool {
30
41
self . thread_id == THREAD_ID . get ( )
31
42
}
@@ -35,11 +46,13 @@ impl<T> SendWrapper<T> {
35
46
/// # Safety
36
47
///
37
48
/// The caller should be in the same thread as the creator.
49
+ #[ inline]
38
50
pub unsafe fn get_unchecked ( & self ) -> & T {
39
51
& self . data
40
52
}
41
53
42
54
/// Returns a reference to the contained value, if valid.
55
+ #[ inline]
43
56
pub fn get ( & self ) -> Option < & T > {
44
57
if self . valid ( ) { Some ( & self . data ) } else { None }
45
58
}
0 commit comments