1212} ;
1313
1414use crate :: error:: { Error , Result } ;
15- use crate :: state:: LuaGuard ;
15+ use crate :: state:: Lua ;
1616use crate :: types:: ValueRef ;
1717
1818/// Handle to an internal Lua string.
@@ -103,9 +103,10 @@ impl String {
103103 BorrowedBytes ( bytes, guard)
104104 }
105105
106- unsafe fn to_slice ( & self ) -> ( & [ u8 ] , LuaGuard ) {
107- let lua = self . 0 . lua . lock ( ) ;
108- let ref_thread = lua. ref_thread ( ) ;
106+ unsafe fn to_slice ( & self ) -> ( & [ u8 ] , Lua ) {
107+ let lua = self . 0 . lua . upgrade ( ) ;
108+ let rawlua = lua. lock ( ) ;
109+ let ref_thread = rawlua. ref_thread ( ) ;
109110 unsafe {
110111 mlua_debug_assert ! (
111112 ffi:: lua_type( ref_thread, self . 0 . index) == ffi:: LUA_TSTRING ,
@@ -117,6 +118,7 @@ impl String {
117118 // string type
118119 let data = ffi:: lua_tolstring ( ref_thread, self . 0 . index , & mut size) ;
119120
121+ drop ( rawlua) ;
120122 ( slice:: from_raw_parts ( data as * const u8 , size + 1 ) , lua)
121123 }
122124 }
@@ -211,7 +213,7 @@ impl Serialize for String {
211213}
212214
213215/// A borrowed string (`&str`) that holds a strong reference to the Lua state.
214- pub struct BorrowedStr < ' a > ( & ' a str , #[ allow( unused) ] LuaGuard ) ;
216+ pub struct BorrowedStr < ' a > ( & ' a str , #[ allow( unused) ] Lua ) ;
215217
216218impl Deref for BorrowedStr < ' _ > {
217219 type Target = str ;
@@ -267,7 +269,7 @@ where
267269}
268270
269271/// A borrowed byte slice (`&[u8]`) that holds a strong reference to the Lua state.
270- pub struct BorrowedBytes < ' a > ( & ' a [ u8 ] , #[ allow( unused) ] LuaGuard ) ;
272+ pub struct BorrowedBytes < ' a > ( & ' a [ u8 ] , #[ allow( unused) ] Lua ) ;
271273
272274impl Deref for BorrowedBytes < ' _ > {
273275 type Target = [ u8 ] ;
@@ -333,4 +335,8 @@ mod assertions {
333335 static_assertions:: assert_not_impl_any!( String : Send ) ;
334336 #[ cfg( feature = "send" ) ]
335337 static_assertions:: assert_impl_all!( String : Send , Sync ) ;
338+ #[ cfg( feature = "send" ) ]
339+ static_assertions:: assert_impl_all!( BorrowedBytes : Send , Sync ) ;
340+ #[ cfg( feature = "send" ) ]
341+ static_assertions:: assert_impl_all!( BorrowedStr : Send , Sync ) ;
336342}
0 commit comments