11#![ doc = include_str ! ( "../README.md" ) ] // This also allow to run examples in that file.
22#![ allow( unsafe_code) ]
3- #![ warn( missing_docs) ]
4- #![ warn( clippy:: pedantic) ]
53#![ deny( clippy:: complexity) ]
64#![ deny( clippy:: cognitive_complexity) ]
7- #![ allow( clippy:: needless_return) ] // To avoid surprise in devs more familiar with languages where return is always explicit
85#![ doc( html_no_source) ]
96#![ no_std]
107
@@ -18,9 +15,6 @@ extern crate std;
1815#[ cfg( feature = "std" ) ]
1916use std:: boxed:: Box ;
2017
21- #[ cfg( all( feature = "std" , feature = "c-types" ) ) ]
22- pub mod c;
23-
2418pub mod error;
2519use error:: PointerError ;
2620
@@ -40,56 +34,42 @@ mod validation;
4034#[ inline]
4135pub fn raw < T > ( data : T ) -> Result < * mut T , PointerError > {
4236 let pointer = Box :: into_raw ( Box :: new ( data) ) ;
37+
4338 #[ cfg( all( feature = "std" , feature = "lender" ) ) ]
4439 lender:: lend ( pointer) ?;
45- return Ok ( pointer) ;
40+
41+ Ok ( pointer)
4642}
4743
48- /// Call to [`own_back<T>()`] ignoring the result.
49- ///
50- /// This is deprecated and will be removed in the version 0.9.0 then you can do this:
44+ /// Opposite of [`raw<T>()`], to use Rust's ownership as usually.
5145///
52- /// ```no_run
46+ /// ```
5347/// # let value = 0;
5448/// # let pointer = opaque_pointer::raw(value).unwrap();
55- /// std::mem:: drop(unsafe { opaque_pointer::own_back(pointer) });
49+ /// drop(unsafe { opaque_pointer::own_back(pointer) });
5650/// ```
5751///
58- /// # Safety
59- ///
60- /// See [`own_back<T>()`] reference doc.
61- #[ deprecated(
62- since = "0.7.2" ,
63- note = "Use own_back<T>() instead, it'll be removed at version 0.9.0"
64- ) ]
65- #[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
66- #[ inline]
67- pub unsafe fn free < T > ( pointer : * mut T ) {
68- core:: mem:: drop ( own_back ( pointer) ) ;
69- }
70-
71- /// Opposite of [`raw<T>()`], to use Rust's ownership as usually.
72- ///
7352/// # Errors
7453///
7554/// The pointer must be not null as it is an obvious invalid pointer.
7655///
7756/// # Safety
7857///
7958/// Invalid pointer or call it twice could cause an undefined behavior or heap error and a crash.
80- #[ doc( alias = "free" ) ]
8159#[ cfg( any( feature = "alloc" , feature = "std" ) ) ]
8260#[ inline]
8361#[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
8462pub unsafe fn own_back < T > ( pointer : * mut T ) -> Result < T , PointerError > {
8563 validation:: lent_pointer ( pointer) ?;
8664 let boxed = { Box :: from_raw ( pointer) } ;
65+
8766 #[ cfg( all( feature = "std" , feature = "lender" ) ) ]
8867 lender:: retrieve ( pointer) ;
89- return Ok ( * boxed) ;
68+
69+ Ok ( * boxed)
9070}
9171
92- /// Reference to a object but without to own it.
72+ /// Reference to an object but without to own it.
9373///
9474/// # Errors
9575///
@@ -101,7 +81,7 @@ pub unsafe fn own_back<T>(pointer: *mut T) -> Result<T, PointerError> {
10181#[ inline]
10282pub unsafe fn object < ' a , T > ( pointer : * const T ) -> Result < & ' a T , PointerError > {
10383 validation:: not_null_pointer ( pointer) ?;
104- return Ok ( & * pointer) ;
84+ Ok ( & * pointer)
10585}
10686
10787/// Mutable reference to a object but without back to own it.
@@ -116,5 +96,5 @@ pub unsafe fn object<'a, T>(pointer: *const T) -> Result<&'a T, PointerError> {
11696#[ inline]
11797pub unsafe fn mut_object < ' a , T > ( pointer : * mut T ) -> Result < & ' a mut T , PointerError > {
11898 validation:: not_null_pointer ( pointer) ?;
119- return Ok ( & mut * pointer) ;
99+ Ok ( & mut * pointer)
120100}
0 commit comments