summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2024-04-05 12:32:14 +0100
committerAlex Orlenko <zxteam@protonmail.com>2024-04-05 12:44:08 +0100
commitad31bed1db761503d6b3e0e3df292548449ad0ff (patch)
tree17d7a2fe793e03f6cd6c75b5b87fab79425db55c
parent62f0bb97b019081e286f7eb5eafe62f09519349e (diff)
downloadmlua-ad31bed1db761503d6b3e0e3df292548449ad0ff.zip
Minor improvements in serializing:
Use `&str` instead of creating Lua string when serializing tuple variant and struct variant
-rw-r--r--src/serde/ser.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/serde/ser.rs b/src/serde/ser.rs
index 3401693..6ee57a1 100644
--- a/src/serde/ser.rs
+++ b/src/serde/ser.rs
@@ -3,7 +3,6 @@ use serde::{ser, Serialize};
use super::LuaSerdeExt;
use crate::error::{Error, Result};
use crate::lua::Lua;
-use crate::string::String;
use crate::table::Table;
use crate::value::{IntoLua, Value};
@@ -287,7 +286,7 @@ impl<'lua> ser::Serializer for Serializer<'lua> {
_len: usize,
) -> Result<Self::SerializeTupleVariant> {
Ok(SerializeTupleVariant {
- name: self.lua.create_string(variant)?,
+ variant,
table: self.lua.create_table()?,
options: self.options,
})
@@ -331,7 +330,7 @@ impl<'lua> ser::Serializer for Serializer<'lua> {
len: usize,
) -> Result<Self::SerializeStructVariant> {
Ok(SerializeStructVariant {
- name: self.lua.create_string(variant)?,
+ variant,
table: self.lua.create_table_with_capacity(0, len)?,
options: self.options,
})
@@ -438,7 +437,7 @@ impl<'lua> ser::SerializeTupleStruct for SerializeSeq<'lua> {
#[doc(hidden)]
pub struct SerializeTupleVariant<'lua> {
- name: String<'lua>,
+ variant: &'static str,
table: Table<'lua>,
options: Options,
}
@@ -458,7 +457,7 @@ impl<'lua> ser::SerializeTupleVariant for SerializeTupleVariant<'lua> {
fn end(self) -> Result<Value<'lua>> {
let lua = self.table.0.lua;
let table = lua.create_table()?;
- table.raw_set(self.name, self.table)?;
+ table.raw_set(self.variant, self.table)?;
Ok(Value::Table(table))
}
}
@@ -553,7 +552,7 @@ impl<'lua> ser::SerializeStruct for SerializeStruct<'lua> {
#[doc(hidden)]
pub struct SerializeStructVariant<'lua> {
- name: String<'lua>,
+ variant: &'static str,
table: Table<'lua>,
options: Options,
}
@@ -575,7 +574,7 @@ impl<'lua> ser::SerializeStructVariant for SerializeStructVariant<'lua> {
fn end(self) -> Result<Value<'lua>> {
let lua = self.table.0.lua;
let table = lua.create_table_with_capacity(0, 1)?;
- table.raw_set(self.name, self.table)?;
+ table.raw_set(self.variant, self.table)?;
Ok(Value::Table(table))
}
}