diff options
author | kyren <kerriganw@gmail.com> | 2017-06-24 20:57:04 -0400 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2017-06-24 20:57:04 -0400 |
commit | 3deb6df525369f8b298b8ce0649f7b1dce6d13df (patch) | |
tree | dd6571235a505f9f73479548fb169612be0d3862 /src/conversion.rs | |
parent | 47db72cac47bf6fc3d09fa0747997a102d41df9c (diff) | |
download | mlua-3deb6df525369f8b298b8ce0649f7b1dce6d13df.zip |
Lots of LuaError changes
It is possible that I have gone too far here into error discrimination and
should scale it back, not sure yet.
Diffstat (limited to 'src/conversion.rs')
-rw-r--r-- | src/conversion.rs | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/src/conversion.rs b/src/conversion.rs index 42b3bfa..98a68d4 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -38,9 +38,9 @@ impl<'lua> FromLua<'lua> for LuaTable<'lua> { fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<LuaTable<'lua>> { match value { LuaValue::Table(table) => Ok(table), - _ => Err(LuaError::ConversionError( - "cannot convert lua value to table".to_owned(), - )), + _ => Err( + LuaConversionError::FromLua("cannot convert lua value to table".to_owned()).into(), + ), } } } @@ -55,9 +55,10 @@ impl<'lua> FromLua<'lua> for LuaFunction<'lua> { fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<LuaFunction<'lua>> { match value { LuaValue::Function(table) => Ok(table), - _ => Err(LuaError::ConversionError( - "cannot convert lua value to function".to_owned(), - )), + _ => Err( + LuaConversionError::FromLua("cannot convert lua value to function".to_owned()) + .into(), + ), } } } @@ -72,9 +73,10 @@ impl<'lua> FromLua<'lua> for LuaUserData<'lua> { fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<LuaUserData<'lua>> { match value { LuaValue::UserData(ud) => Ok(ud), - _ => Err(LuaError::ConversionError( - "cannot convert lua value to userdata".to_owned(), - )), + _ => Err( + LuaConversionError::FromLua("cannot convert lua value to userdata".to_owned()) + .into(), + ), } } } @@ -89,9 +91,10 @@ impl<'lua> FromLua<'lua> for LuaThread<'lua> { fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<LuaThread<'lua>> { match value { LuaValue::Thread(t) => Ok(t), - _ => Err(LuaError::ConversionError( - "cannot convert lua value to thread".to_owned(), - )), + _ => Err( + LuaConversionError::FromLua("cannot convert lua value to thread".to_owned()) + .into(), + ), } } } @@ -106,9 +109,10 @@ impl<'lua, T: LuaUserDataType + Copy> FromLua<'lua> for T { fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<T> { match value { LuaValue::UserData(ud) => Ok(*ud.borrow::<T>()?), - _ => Err(LuaError::ConversionError( - "cannot convert lua value to userdata".to_owned(), - )), + _ => Err( + LuaConversionError::FromLua("cannot convert lua value to userdata".to_owned()) + .into(), + ), } } } @@ -139,9 +143,11 @@ impl<'lua> FromLua<'lua> for LightUserData { fn from_lua(v: LuaValue, _: &'lua Lua) -> LuaResult<Self> { match v { LuaValue::LightUserData(ud) => Ok(ud), - _ => Err(LuaError::ConversionError( - "cannot convert lua value to lightuserdata".to_owned(), - )), + _ => Err( + LuaConversionError::FromLua( + "cannot convert lua value to lightuserdata".to_owned(), + ).into(), + ), } } } @@ -221,9 +227,10 @@ impl<'lua, T: FromLua<'lua>> FromLua<'lua> for Vec<T> { if let LuaValue::Table(table) = value { table.sequence_values().collect() } else { - Err(LuaError::ConversionError( - "cannot convert lua value to table for Vec".to_owned(), - )) + Err( + LuaConversionError::FromLua("cannot convert lua value to table for Vec".to_owned()) + .into(), + ) } } } @@ -239,9 +246,11 @@ impl<'lua, K: Eq + Hash + FromLua<'lua>, V: FromLua<'lua>> FromLua<'lua> for Has if let LuaValue::Table(table) = value { table.pairs().collect() } else { - Err(LuaError::ConversionError( - "cannot convert lua value to table for HashMap".to_owned(), - )) + Err( + LuaConversionError::FromLua( + "cannot convert lua value to table for HashMap".to_owned(), + ).into(), + ) } } } @@ -257,9 +266,11 @@ impl<'lua, K: Ord + FromLua<'lua>, V: FromLua<'lua>> FromLua<'lua> for BTreeMap< if let LuaValue::Table(table) = value { table.pairs().collect() } else { - Err(LuaError::ConversionError( - "cannot convert lua value to table for BTreeMap".to_owned(), - )) + Err( + LuaConversionError::FromLua( + "cannot convert lua value to table for BTreeMap".to_owned(), + ).into(), + ) } } } |