into()
This commit is contained in:
parent
ca89d343c3
commit
e2478bfbf4
28
src/types.rs
28
src/types.rs
|
|
@ -8,6 +8,34 @@ pub enum ValueInner {
|
||||||
Table(Table),
|
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>;
|
pub type Value = Option<ValueInner>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user