wasmedge_tensorflow_interface 0.3.0

A Rust library that provides Rust to WebAssembly developers with syntax for using tensorflow functionality
Documentation
// This file is automatically generated, DO NOT EDIT
//
// To regenerate this file run the `crates/witx-bindgen` command

use core::fmt;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct WasmedgeImageErrno(u32);
pub const WASMEDGE_IMAGE_ERRNO_SUCCESS: WasmedgeImageErrno = WasmedgeImageErrno(0);
pub const WASMEDGE_IMAGE_ERRNO_FAIL: WasmedgeImageErrno = WasmedgeImageErrno(1);
impl WasmedgeImageErrno {
    pub const fn raw(&self) -> u32 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "SUCCESS",
            1 => "FAIL",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "",
            1 => "",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for WasmedgeImageErrno {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("WasmedgeImageErrno")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}
impl fmt::Display for WasmedgeImageErrno {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{} (error {})", self.name(), self.0)
    }
}

#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
impl std::error::Error for WasmedgeImageErrno {}

#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct WasmedgeImageRawType(u32);
pub const WASMEDGE_IMAGE_RAW_TYPE_RGB8: WasmedgeImageRawType = WasmedgeImageRawType(0);
pub const WASMEDGE_IMAGE_RAW_TYPE_BGR8: WasmedgeImageRawType = WasmedgeImageRawType(1);
pub const WASMEDGE_IMAGE_RAW_TYPE_RGB32F: WasmedgeImageRawType = WasmedgeImageRawType(2);
pub const WASMEDGE_IMAGE_RAW_TYPE_BGR32F: WasmedgeImageRawType = WasmedgeImageRawType(3);
impl WasmedgeImageRawType {
    pub const fn raw(&self) -> u32 {
        self.0
    }

    pub fn name(&self) -> &'static str {
        match self.0 {
            0 => "RGB8",
            1 => "BGR8",
            2 => "RGB32F",
            3 => "BGR32F",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
    pub fn message(&self) -> &'static str {
        match self.0 {
            0 => "",
            1 => "",
            2 => "",
            3 => "",
            _ => unsafe { core::hint::unreachable_unchecked() },
        }
    }
}
impl fmt::Debug for WasmedgeImageRawType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("WasmedgeImageRawType")
            .field("code", &self.0)
            .field("name", &self.name())
            .field("message", &self.message())
            .finish()
    }
}

pub type ImgBuffer<'a> = &'a [u8];
pub type BufMaxSize = u32;
pub unsafe fn load_jpg(
    input_img_buffer: ImgBuffer<'_>,
    out_width: u32,
    out_height: u32,
    data_type: WasmedgeImageRawType,
    output_buf: *mut u8,
    output_buf_max_size: BufMaxSize,
) -> Result<(), WasmedgeImageErrno> {
    let ret = wasmedge_image::load_jpg(
        input_img_buffer.as_ptr() as i32,
        input_img_buffer.len() as i32,
        out_width as i32,
        out_height as i32,
        data_type.0 as i32,
        output_buf as i32,
        output_buf_max_size as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(WasmedgeImageErrno(ret as u32)),
    }
}

pub unsafe fn load_png(
    input_img_buffer: ImgBuffer<'_>,
    out_width: u32,
    out_height: u32,
    data_type: WasmedgeImageRawType,
    output_buf: *mut u8,
    output_buf_max_size: BufMaxSize,
) -> Result<(), WasmedgeImageErrno> {
    let ret = wasmedge_image::load_png(
        input_img_buffer.as_ptr() as i32,
        input_img_buffer.len() as i32,
        out_width as i32,
        out_height as i32,
        data_type.0 as i32,
        output_buf as i32,
        output_buf_max_size as i32,
    );
    match ret {
        0 => Ok(()),
        _ => Err(WasmedgeImageErrno(ret as u32)),
    }
}

pub mod wasmedge_image {
    #[link(wasm_import_module = "wasmedge_image")]
    extern "C" {
        pub fn load_jpg(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
        ) -> i32;
        pub fn load_png(
            arg0: i32,
            arg1: i32,
            arg2: i32,
            arg3: i32,
            arg4: i32,
            arg5: i32,
            arg6: i32,
        ) -> i32;
    }
}