File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -13,4 +13,5 @@ repository = "https://github.com/jhg/opaque-pointer-rs/"
13
13
[features ]
14
14
default = [" std" ]
15
15
std = []
16
+ alloc = []
16
17
c-types = []
Original file line number Diff line number Diff line change 10
10
11
11
#![ no_std]
12
12
13
- #[ cfg( not( feature = "std" ) ) ]
13
+ #[ cfg( all ( feature = "alloc" , not( feature = "std" ) ) ) ]
14
14
extern crate alloc;
15
- #[ cfg( not( feature = "std" ) ) ]
15
+ #[ cfg( all ( feature = "alloc" , not( feature = "std" ) ) ) ]
16
16
use alloc:: boxed:: Box ;
17
17
18
18
#[ cfg( feature = "std" ) ]
@@ -32,6 +32,7 @@ fn panic_if_null<T>(pointer: *const T) {
32
32
}
33
33
34
34
/// Convert type to raw pointer.
35
+ #[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
35
36
#[ inline]
36
37
pub fn raw < T > ( data : T ) -> * mut T {
37
38
return Box :: into_raw ( Box :: new ( data) ) ;
@@ -42,6 +43,7 @@ pub fn raw<T>(data: T) -> *mut T {
42
43
/// # Safety
43
44
///
44
45
/// Never call it twice. That could produce a HEAP error that produce a crash.
46
+ #[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
45
47
#[ inline]
46
48
pub unsafe fn free < T > ( pointer : * mut T ) {
47
49
if pointer. is_null ( ) {
@@ -60,6 +62,7 @@ pub unsafe fn free<T>(pointer: *mut T) {
60
62
/// # Safety
61
63
///
62
64
/// Never call it twice. That could produce a HEAP error that produce a crash.
65
+ #[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
63
66
#[ inline]
64
67
pub unsafe fn own_back < T > ( pointer : * mut T ) -> T {
65
68
panic_if_null ( pointer) ;
You can’t perform that action at this time.
0 commit comments