use std::ops::Deref;
use js_sys::{Array, Function, Reflect};
use wasm_bindgen::JsValue;
#[derive(Clone, Eq, PartialEq, Debug, Default)]
pub struct GeneratedConstructor(pub Function);
impl Deref for GeneratedConstructor {
type Target = Function;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl AsRef<Function> for GeneratedConstructor {
fn as_ref(&self) -> &Function {
&self.0
}
}
impl AsMut<Function> for GeneratedConstructor {
fn as_mut(&mut self) -> &mut Function {
&mut self.0
}
}
impl GeneratedConstructor {
pub fn construct(&self) -> Result<Function, JsValue> {
Reflect::construct(self, &Array::new()).map(|js_value| js_value.into())
}
pub fn construct_with_arguments(
&self,
args: impl AsRef<[JsValue]>,
) -> Result<Function, JsValue> {
self.construct_with_array_arguments(&Array::from_iter(args.as_ref()))
}
#[doc(hidden)]
pub fn construct_with_array_arguments(&self, args: &Array) -> Result<Function, JsValue> {
Reflect::construct(self, args).map(|js_value| js_value.into())
}
pub fn inner(&self) -> &Function {
&self.0
}
pub fn to_inner(&self) -> Function {
self.0.clone()
}
pub fn into_inner(self) -> Function {
self.0
}
}