12
12
} ;
13
13
14
14
use crate :: error:: { Error , Result } ;
15
- use crate :: state:: LuaGuard ;
15
+ use crate :: state:: Lua ;
16
16
use crate :: types:: ValueRef ;
17
17
18
18
/// Handle to an internal Lua string.
@@ -103,9 +103,10 @@ impl String {
103
103
BorrowedBytes ( bytes, guard)
104
104
}
105
105
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 ( ) ;
109
110
unsafe {
110
111
mlua_debug_assert ! (
111
112
ffi:: lua_type( ref_thread, self . 0 . index) == ffi:: LUA_TSTRING ,
@@ -117,6 +118,7 @@ impl String {
117
118
// string type
118
119
let data = ffi:: lua_tolstring ( ref_thread, self . 0 . index , & mut size) ;
119
120
121
+ drop ( rawlua) ;
120
122
( slice:: from_raw_parts ( data as * const u8 , size + 1 ) , lua)
121
123
}
122
124
}
@@ -211,7 +213,7 @@ impl Serialize for String {
211
213
}
212
214
213
215
/// 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 ) ;
215
217
216
218
impl Deref for BorrowedStr < ' _ > {
217
219
type Target = str ;
@@ -267,7 +269,7 @@ where
267
269
}
268
270
269
271
/// 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 ) ;
271
273
272
274
impl Deref for BorrowedBytes < ' _ > {
273
275
type Target = [ u8 ] ;
@@ -333,4 +335,8 @@ mod assertions {
333
335
static_assertions:: assert_not_impl_any!( String : Send ) ;
334
336
#[ cfg( feature = "send" ) ]
335
337
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 ) ;
336
342
}
0 commit comments