weakauras_codec_lua_value/error.rs
1// Copyright 2025 Velithris
2// SPDX-License-Identifier: MIT
3
4use core::fmt;
5use std::error;
6
7/// The error type returned when conversion from [LuaValue] to [LuaMapKey] fails.
8///
9/// [LuaValue]: crate::LuaValue
10/// [LuaMapKey]: crate::LuaMapKey
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub enum TryFromLuaValueError {
13 /// Attempt to convert a [LuaValue::Null](crate::LuaValue::Null) into a [LuaMapKey](crate::LuaMapKey).
14 KeyCannotBeNan,
15 /// Attempt to convert a [LuaValue::Number](crate::LuaValue::Number) that is NaN into a [LuaMapKey](crate::LuaMapKey).
16 KeyCannotBeNull,
17}
18
19impl fmt::Display for TryFromLuaValueError {
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21 match self {
22 Self::KeyCannotBeNan => write!(
23 f,
24 "LuaMapKey can't be constructed from LuaValue::Number that is NaN"
25 ),
26 Self::KeyCannotBeNull => {
27 write!(f, "LuaMapKey can't be constructed from LuaValue::Null")
28 }
29 }
30 }
31}
32
33impl error::Error for TryFromLuaValueError {}