Skip to content

Commit 3ab3c99

Browse files
authored
feat: support external strings for Cow<str> and Cow<CStr> (#692)
1 parent 5872ed7 commit 3ab3c99

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/conversion.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,10 @@ impl IntoLua for &str {
523523
impl IntoLua for Cow<'_, str> {
524524
#[inline]
525525
fn into_lua(self, lua: &Lua) -> Result<Value> {
526-
Ok(Value::String(lua.create_string(self.as_bytes())?))
526+
match self {
527+
Cow::Borrowed(s) => s.into_lua(lua),
528+
Cow::Owned(s) => s.into_lua(lua),
529+
}
527530
}
528531
}
529532

@@ -585,7 +588,10 @@ impl IntoLua for &CStr {
585588
impl IntoLua for Cow<'_, CStr> {
586589
#[inline]
587590
fn into_lua(self, lua: &Lua) -> Result<Value> {
588-
Ok(Value::String(lua.create_string(self.to_bytes())?))
591+
match self {
592+
Cow::Borrowed(s) => s.into_lua(lua),
593+
Cow::Owned(s) => s.into_lua(lua),
594+
}
589595
}
590596
}
591597

0 commit comments

Comments
 (0)