From f24fdfdb80c20736ac1ca9f18913caf807d6a6c7 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Mon, 21 Jun 2021 23:19:33 +0100 Subject: Update `AsChunk::env` function prototype --- mlua_derive/src/lib.rs | 6 +++--- src/lua.rs | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/mlua_derive/src/lib.rs b/mlua_derive/src/lib.rs index 152e675..3dd3bab 100644 --- a/mlua_derive/src/lib.rs +++ b/mlua_derive/src/lib.rs @@ -77,15 +77,15 @@ pub fn chunk(input: TokenStream) -> TokenStream { (#source).as_bytes() } - fn env(&self, lua: &'lua Lua) -> Option>> { + fn env(&self, lua: &'lua Lua) -> Result>> { if #caps_len > 0 { if let Ok(mut make_env) = self.0.lock() { if let Some(make_env) = make_env.take() { - return Some(make_env(lua)); + return make_env(lua).map(Some); } } } - None + Ok(None) } fn mode(&self) -> Option { diff --git a/src/lua.rs b/src/lua.rs index edc030d..87645a7 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -2074,7 +2074,7 @@ pub struct Chunk<'lua, 'a> { lua: &'lua Lua, source: &'a [u8], name: Option, - env: Option>>, + env: Result>>, mode: Option, } @@ -2101,8 +2101,8 @@ pub trait AsChunk<'lua> { /// Returns optional chunk [environment] /// /// [environment]: https://www.lua.org/manual/5.3/manual.html#2.2 - fn env(&self, _lua: &'lua Lua) -> Option>> { - None + fn env(&self, _lua: &'lua Lua) -> Result>> { + Ok(None) } /// Returns optional chunk mode (text or binary) @@ -2137,7 +2137,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> { /// useful. pub fn set_environment>(mut self, env: V) -> Result> { // Prefer to propagate errors here and wrap to `Ok` - self.env = Some(Ok(env.to_lua(self.lua)?)); + self.env = Ok(Some(env.to_lua(self.lua)?)); Ok(self) } @@ -2268,10 +2268,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> { } fn env(&self) -> Result>> { - match self.env { - None => Ok(None), - Some(ref env) => env.clone().map(Some), - } + self.env.clone() } fn expression_source(&self) -> Vec { -- cgit v1.2.3