[oden] Garbage assets, need to rewrite to IO
This commit is contained in:
parent
75fcc427ac
commit
17805fa4a6
17 changed files with 240 additions and 94 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{ContextRef, Error, Result, Value, ValueRef};
|
||||
use crate::{ContextRef, Error, Result, Value, ValueRef, ValueType};
|
||||
use std::num::TryFromIntError;
|
||||
|
||||
pub trait TryFromValue: Sized {
|
||||
|
|
@ -105,10 +105,24 @@ impl TryFromValue for Value {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFromValue for () {
|
||||
#[inline]
|
||||
fn try_from_value(value: &ValueRef, _ctx: &ContextRef) -> Result<Self> {
|
||||
if value.is_undefined() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::InvalidType {
|
||||
expected: ValueType::Undefined,
|
||||
found: value.value_type(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TryFromValue> TryFromValue for Option<T> {
|
||||
#[inline]
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
if value.is_undefined() {
|
||||
if value.is_null() || value.is_undefined() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(T::try_from_value(value, ctx)?))
|
||||
|
|
|
|||
|
|
@ -7,21 +7,21 @@ pub trait TryIntoValue {
|
|||
impl TryIntoValue for u8 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
|
||||
ctx.new_u64(self)
|
||||
ctx.new_u32(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryIntoValue for u16 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
|
||||
ctx.new_u64(self)
|
||||
ctx.new_u32(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryIntoValue for u32 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
|
||||
ctx.new_u64(self)
|
||||
ctx.new_u32(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ impl TryIntoValue for Error {
|
|||
}
|
||||
Error::ConversionError(e) => Err(Error::ConversionError(e)),
|
||||
Error::RustFunctionError(e) => Err(Error::RustFunctionError(e)),
|
||||
Error::Exception(v, d) => Err(Error::Exception(v.dup(ctx), d)),
|
||||
Error::Exception(v, d, s) => Err(Error::Exception(v.dup(ctx), d, s)),
|
||||
Error::OutOfMemory => Err(Error::OutOfMemory),
|
||||
Error::IOError(e) => Err(Error::IOError(e)),
|
||||
Error::ParseError(name, err) => Err(Error::ParseError(name, err)),
|
||||
|
|
@ -135,8 +135,15 @@ impl<T: TryIntoValue> TryIntoValue for Option<T> {
|
|||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
|
||||
match self {
|
||||
None => Ok(ctx.undefined()),
|
||||
None => Ok(ctx.null()),
|
||||
Some(v) => v.try_into_value(ctx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryIntoValue for () {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
|
||||
Ok(ctx.undefined())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue