@@ -13,20 +13,21 @@ thread_local! {
1313/// Returns `true` if there is currently an error.
1414#[ no_mangle]
1515pub extern "C" fn mj_err_is_set ( ) -> bool {
16- LAST_ERROR . with_borrow ( |x| x. is_some ( ) )
16+ LAST_ERROR . with ( |x| x. borrow ( ) . is_some ( ) )
1717}
1818
1919/// Clears the current error.
2020#[ no_mangle]
2121pub extern "C" fn mj_err_clear ( ) {
22- LAST_ERROR . with_borrow_mut ( |x| * x = None ) ;
22+ LAST_ERROR . with ( |x| * x. borrow_mut ( ) = None ) ;
2323}
2424
2525/// Prints the error to stderr.
2626#[ no_mangle]
2727pub extern "C" fn mj_err_print ( ) -> bool {
28- LAST_ERROR . with_borrow ( |x| {
29- if let Some ( err) = x {
28+ LAST_ERROR . with ( |x| {
29+ let x = x. borrow ( ) ;
30+ if let Some ( err) = x. as_ref ( ) {
3031 eprintln ! ( "error: {err}" ) ;
3132 if err. name ( ) . is_some ( ) {
3233 eprintln ! ( "{}" , err. display_debug_info( ) ) ;
@@ -55,8 +56,9 @@ pub extern "C" fn mj_err_print() -> bool {
5556#[ no_mangle]
5657pub unsafe extern "C" fn mj_err_get_debug_info ( ) -> * mut c_char {
5758 LAST_ERROR
58- . with_borrow ( |x| {
59- x. as_ref ( )
59+ . with ( |x| {
60+ x. borrow ( )
61+ . as_ref ( )
6062 . and_then ( |x| {
6163 let mut info = String :: new ( ) ;
6264 if x. name ( ) . is_some ( ) {
@@ -92,8 +94,9 @@ pub unsafe extern "C" fn mj_err_get_debug_info() -> *mut c_char {
9294#[ no_mangle]
9395pub unsafe extern "C" fn mj_err_get_detail ( ) -> * mut c_char {
9496 LAST_ERROR
95- . with_borrow ( |x| {
96- x. as_ref ( )
97+ . with ( |x| {
98+ x. borrow ( )
99+ . as_ref ( )
97100 . and_then ( |x| x. detail ( ) )
98101 . and_then ( |detail| CString :: new ( detail) . ok ( ) )
99102 . map ( |cstr| cstr. into_raw ( ) )
@@ -107,8 +110,9 @@ pub unsafe extern "C" fn mj_err_get_detail() -> *mut c_char {
107110#[ no_mangle]
108111pub unsafe extern "C" fn mj_err_get_template_name ( ) -> * mut c_char {
109112 LAST_ERROR
110- . with_borrow ( |x| {
111- x. as_ref ( )
113+ . with ( |x| {
114+ x. borrow ( )
115+ . as_ref ( )
112116 . and_then ( |x| x. name ( ) )
113117 . and_then ( |name| CString :: new ( name) . ok ( ) )
114118 . map ( |cstr| cstr. into_raw ( ) )
@@ -120,7 +124,7 @@ pub unsafe extern "C" fn mj_err_get_template_name() -> *mut c_char {
120124#[ no_mangle]
121125pub unsafe extern "C" fn mj_err_get_line ( ) -> u32 {
122126 LAST_ERROR
123- . with_borrow ( |x| x. as_ref ( ) . and_then ( |x| x. line ( ) ) )
127+ . with ( |x| x. borrow ( ) . as_ref ( ) . and_then ( |x| x. line ( ) ) )
124128 . unwrap_or ( 0 ) as _
125129}
126130
@@ -180,8 +184,9 @@ impl TryFrom<ErrorKind> for mj_err_kind {
180184#[ no_mangle]
181185pub unsafe extern "C" fn mj_err_get_kind ( ) -> mj_err_kind {
182186 LAST_ERROR
183- . with_borrow ( |x| {
184- x. as_ref ( )
187+ . with ( |x| {
188+ x. borrow ( )
189+ . as_ref ( )
185190 . and_then ( |x| mj_err_kind:: try_from ( x. kind ( ) ) . ok ( ) )
186191 } )
187192 . unwrap_or ( mj_err_kind:: MJ_ERR_KIND_UNKNOWN )
0 commit comments