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 { 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)) } fn from_raw_unchecked(env: sys::napi_env, value: sys::napi_value) -> Either { Self::from_raw(env, value).unwrap() } fn raw_value(&self) -> sys::napi_value { match self { Either::A(v) => v.raw_value(), Either::B(v) => v.raw_value(), } } }