From 6cbe895262abb012c829f9944368b2ca48281e5a Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 8 Apr 2026 20:16:13 +0800 Subject: [PATCH] feat: support external strings for `Cow` and `Cow` --- src/conversion.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/conversion.rs b/src/conversion.rs index f2f7ca5a..301d37ef 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -523,7 +523,10 @@ impl IntoLua for &str { impl IntoLua for Cow<'_, str> { #[inline] fn into_lua(self, lua: &Lua) -> Result { - Ok(Value::String(lua.create_string(self.as_bytes())?)) + match self { + Cow::Borrowed(s) => s.into_lua(lua), + Cow::Owned(s) => s.into_lua(lua), + } } } @@ -585,7 +588,10 @@ impl IntoLua for &CStr { impl IntoLua for Cow<'_, CStr> { #[inline] fn into_lua(self, lua: &Lua) -> Result { - Ok(Value::String(lua.create_string(self.to_bytes())?)) + match self { + Cow::Borrowed(s) => s.into_lua(lua), + Cow::Owned(s) => s.into_lua(lua), + } } }