[oden] Grab my incomplete QuickJS wrapper
This commit is contained in:
parent
aa70df41a3
commit
898b1fe129
114 changed files with 244181 additions and 0 deletions
129
oden-js/src/conversion/into.rs
Normal file
129
oden-js/src/conversion/into.rs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
use crate::{Class, ContextRef, Error, Value, ValueRef, ValueResult};
|
||||
|
||||
pub trait TryIntoValue<'r> {
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r>;
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for u8 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_u64(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for u16 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_u64(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for u32 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_u64(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for u64 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_u64(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for i8 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_i32(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for i16 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_i32(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for i32 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_i32(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for i64 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_i64(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for f32 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_f64(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for f64 {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_f64(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for bool {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_bool(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for &str {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
ctx.new_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for &ValueRef<'r> {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
Ok(self.dup(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for Value<'r> {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
Ok(self.dup(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> TryIntoValue<'r> for Error<'r> {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
match self {
|
||||
Error::TooManyClasses => Err(Error::TooManyClasses),
|
||||
Error::WrongClass(c) => Err(Error::WrongClass(c)),
|
||||
Error::UnexpectedNul => Err(Error::UnexpectedNul),
|
||||
Error::DifferentRuntime => Err(Error::DifferentRuntime),
|
||||
Error::InvalidType { expected, found } => Err(Error::InvalidType { expected, found }),
|
||||
Error::ArgumentCountMismatch { expected, received } => {
|
||||
Err(Error::ArgumentCountMismatch { expected, received })
|
||||
}
|
||||
Error::ConversionError(e) => Err(Error::ConversionError(e)),
|
||||
Error::RustFunctionError(e) => Err(Error::RustFunctionError(e)),
|
||||
Error::Exception(v) => Err(Error::Exception(v.dup(ctx))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, T: Class> TryIntoValue<'r> for T {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef<'r>) -> ValueResult<'r> {
|
||||
self.into_value(ctx)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue