@@ -24,26 +24,27 @@ use std::boxed::Box;
2424#[ cfg( all( feature = "std" , feature = "c-types" ) ) ]
2525pub mod c;
2626
27- /// Panic if a pointer is null.
2827#[ inline]
2928fn panic_if_null < T > ( pointer : * const T ) {
3029 if pointer. is_null ( ) {
3130 unreachable ! ( "A null pointer was passed to the library, something is wrong in the C or C++ code" ) ;
3231 }
3332}
3433
35- /// Convert type to raw pointer.
34+ /// Convert type to raw pointer ready to be used as opaque pointer .
3635#[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
3736#[ inline]
3837pub fn raw < T > ( data : T ) -> * mut T {
3938 return Box :: into_raw ( Box :: new ( data) ) ;
4039}
4140
42- /// Free pointer to type.
41+ /// Free memory of a previous type converted to raw pointer .
4342///
4443/// # Safety
4544///
46- /// Never call it twice. That could produce a HEAP error that produce a crash.
45+ /// The pointer must be a valid reference and never call it twice or behavior is undefined.
46+ ///
47+ /// That could produce a HEAP error that produce a crash.
4748#[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
4849#[ inline]
4950pub unsafe fn free < T > ( pointer : * mut T ) {
@@ -58,11 +59,13 @@ pub unsafe fn free<T>(pointer: *mut T) {
5859 // We let drop the boxed data.
5960}
6061
61- /// Own back from a raw pointer.
62+ /// Own back from a raw pointer to use Rust ownership as usually .
6263///
6364/// # Safety
6465///
65- /// Never call it twice. That could produce a HEAP error that produce a crash.
66+ /// The pointer must be a valid reference and never call it twice or behavior is undefined.
67+ ///
68+ /// That could produce a HEAP error that produce a crash.
6669#[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
6770#[ inline]
6871pub unsafe fn own_back < T > ( pointer : * mut T ) -> T {
@@ -72,23 +75,33 @@ pub unsafe fn own_back<T>(pointer: *mut T) -> T {
7275 return * boxed;
7376}
7477
75- /// Convert raw pointer to type to type reference.
78+ /// Convert raw pointer to type to type reference but without back to own it.
79+ ///
80+ /// That's the main difference with `own_back<T>`, it does not back to use ownership
81+ /// and values will not be dropped.
7682///
7783/// # Safety
7884///
79- /// The pointer must be a valid reference to that value with that type.
85+ /// The pointer must be a valid reference and never call it twice or behavior is undefined.
86+ ///
87+ /// That could produce a HEAP error that produce a crash.
8088#[ inline]
8189pub unsafe fn object < ' a , T > ( pointer : * const T ) -> & ' a T {
8290 panic_if_null ( pointer) ;
8391 // CAUTION: this is unsafe
8492 return & * pointer;
8593}
8694
87- /// Convert raw pointer to type into type mutable reference.
95+ /// Convert raw pointer to type into type mutable reference but without back to own it.
96+ ///
97+ /// That's the main difference with `own_back<T>`, it does not back to use ownership
98+ /// and values will not be dropped.
8899///
89100/// # Safety
90101///
91- /// The pointer must be a valid reference to that value with that type.
102+ /// The pointer must be a valid reference and never call it twice or behavior is undefined.
103+ ///
104+ /// That could produce a HEAP error that produce a crash.
92105#[ inline]
93106pub unsafe fn mut_object < ' a , T > ( pointer : * mut T ) -> & ' a mut T {
94107 panic_if_null ( pointer) ;
0 commit comments