Skip to content

Commit bf9fcc5

Browse files
committed
Simplify WrappedString
1 parent 7ce6b97 commit bf9fcc5

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/string.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,20 @@ impl<'a> IntoIterator for BorrowedBytes<'a> {
368368
}
369369
}
370370

371-
pub(crate) struct WrappedString<F: FnOnce(&Lua) -> Result<String>>(F);
371+
pub(crate) struct WrappedString<T: AsRef<[u8]>>(T);
372372

373373
impl String {
374374
/// Wraps bytes, returning an opaque type that implements [`IntoLua`] trait.
375375
///
376376
/// This function uses [`Lua::create_string`] under the hood.
377377
pub fn wrap(data: impl AsRef<[u8]>) -> impl IntoLua {
378-
WrappedString(move |lua| lua.create_string(data))
378+
WrappedString(data)
379379
}
380380
}
381381

382-
impl<F> IntoLua for WrappedString<F>
383-
where
384-
F: FnOnce(&Lua) -> Result<String>,
385-
{
382+
impl<T: AsRef<[u8]>> IntoLua for WrappedString<T> {
386383
fn into_lua(self, lua: &Lua) -> Result<Value> {
387-
(self.0)(lua).map(Value::String)
384+
lua.create_string(self.0).map(Value::String)
388385
}
389386
}
390387

0 commit comments

Comments
 (0)