use crate::{sys, JsUndefined, NapiValue, Result}; #[derive(Debug, Clone, Copy)] pub enum Either { A(A), B(B), } impl Into> for Either { fn into(self) -> Option { match self { Either::A(v) => Some(v), Either::B(_) => None, } } } impl NapiValue for Either { unsafe fn from_raw(env: sys::napi_env, value: sys::napi_value) -> Result> { A::from_raw(env, value) .map(Self::A) .or_else(|_| B::from_raw(env, value).map(Self::B)) } unsafe fn from_raw_unchecked(env: sys::napi_env, value: sys::napi_value) -> Either { Self::from_raw(env, value).unwrap() } unsafe fn raw(&self) -> sys::napi_value { match self { Either::A(v) => v.raw(), Either::B(v) => v.raw(), } } }