neon 1.0.0-alpha.2

A safe abstraction layer for Node.js.
Documentation
use crate::{
    context::internal::Env,
    handle::{Handle, Managed},
    sys::raw,
    types::Value,
};

pub trait ValueInternal: Managed + 'static {
    fn name() -> String;

    fn is_typeof<Other: Value>(env: Env, other: &Other) -> bool;

    fn downcast<Other: Value>(env: Env, other: &Other) -> Option<Self> {
        if Self::is_typeof(env, other) {
            Some(Self::from_raw(env, other.to_raw()))
        } else {
            None
        }
    }

    fn cast<'a, T: Value, F: FnOnce(raw::Local) -> T>(self, f: F) -> Handle<'a, T> {
        Handle::new_internal(f(self.to_raw()))
    }
}