use super::*;
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct BarcodeDetector {
inner: Any,
}
impl FromVal for BarcodeDetector {
fn from_val(v: &Any) -> Self {
BarcodeDetector {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for BarcodeDetector {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for BarcodeDetector {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for BarcodeDetector {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for BarcodeDetector {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<BarcodeDetector> for Any {
fn from(s: BarcodeDetector) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&BarcodeDetector> for Any {
fn from(s: &BarcodeDetector) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(BarcodeDetector);
impl BarcodeDetector {
pub fn new() -> BarcodeDetector {
Self {
inner: Any::global("BarcodeDetector").new(&[]).as_::<Any>(),
}
}
}
impl BarcodeDetector {
pub fn new_with_barcode_detector_options(
barcode_detector_options: &BarcodeDetectorOptions,
) -> BarcodeDetector {
Self {
inner: Any::global("BarcodeDetector")
.new(&[barcode_detector_options.into()])
.as_::<Any>(),
}
}
}
impl BarcodeDetector {
pub fn get_supported_formats() -> Promise<TypedArray<BarcodeFormat>> {
Any::global("BarcodeDetector")
.call("getSupportedFormats", &[])
.as_::<Promise<TypedArray<BarcodeFormat>>>()
}
}
impl BarcodeDetector {
pub fn detect(&self, image: &Any) -> Promise<TypedArray<DetectedBarcode>> {
self.inner
.call("detect", &[image.into()])
.as_::<Promise<TypedArray<DetectedBarcode>>>()
}
}