This commit is contained in:
numzero 2025-04-11 19:48:18 +03:00
parent ca89d343c3
commit e2478bfbf4

View File

@ -8,6 +8,34 @@ pub enum ValueInner {
Table(Table),
}
macro_rules! impl_from {
($as: ident, $from: ty) => {
impl From<$from> for ValueInner {
fn from(value: $from) -> Self {
Self::$as(value.into())
}
}
};
(try $as: ident, $from: ty) => {
impl TryFrom<$from> for ValueInner {
type Error = ::std::num::TryFromIntError;
fn try_from(value: $from) -> Result<Self, Self::Error> {
Ok(Self::$as(value.try_into()?))
}
}
};
}
impl_from!(Boolean, bool);
impl_from!(try Number, isize);
impl_from!(try Number, usize);
impl_from!(try Number, i64);
impl_from!(try Number, u64);
impl_from!(Number, u32);
impl_from!(Number, i32);
impl_from!(String, String);
impl_from!(String, &str);
pub type Value = Option<ValueInner>;
#[derive(Debug, Clone, Default)]