use std::sync::Arc;
#[cfg(any(target_arch = "wasm32", feature = "cef"))]
pub(crate) const ZAP_PARAM_STRING: u32 = 0;
#[cfg(any(target_arch = "wasm32", feature = "cef"))]
pub(crate) const ZAP_PARAM_READ_ONLY_UINT8_BUFFER: u32 = 1;
#[cfg(any(target_arch = "wasm32", feature = "cef"))]
pub(crate) const ZAP_PARAM_UINT8_BUFFER: u32 = 2;
#[cfg(any(target_arch = "wasm32", feature = "cef"))]
pub(crate) const ZAP_PARAM_FLOAT32_BUFFER: u32 = 3;
#[cfg(any(target_arch = "wasm32", feature = "cef"))]
pub(crate) const ZAP_PARAM_READ_ONLY_FLOAT32_BUFFER: u32 = 4;
#[derive(Clone, Debug, PartialEq)]
pub enum ZapParam {
String(String),
ReadOnlyU8Buffer(Arc<Vec<u8>>),
ReadOnlyF32Buffer(Arc<Vec<f32>>),
MutableU8Buffer(Vec<u8>),
MutableF32Buffer(Vec<f32>),
}
impl ZapParam {
pub fn as_str(&self) -> &str {
match self {
ZapParam::String(v) => v,
_ => panic!("ZapParam is not a String"),
}
}
pub fn as_u8_slice(&self) -> &[u8] {
match self {
ZapParam::MutableU8Buffer(v) => v,
ZapParam::ReadOnlyU8Buffer(v) => v,
_ => panic!("{:?} is not a U8Buffer or ReadOnlyU8Buffer", self),
}
}
pub fn as_f32_slice(&self) -> &[f32] {
match self {
ZapParam::MutableF32Buffer(v) => v,
ZapParam::ReadOnlyF32Buffer(v) => v,
_ => panic!("{:?} is not a F32Buffer or ReadOnlyF32Buffer", self),
}
}
pub fn as_arc_vec_u8(&self) -> Arc<Vec<u8>> {
match self {
ZapParam::ReadOnlyU8Buffer(v) => Arc::clone(v),
_ => panic!("{:?} is not a ReadOnlyU8Buffer", self),
}
}
pub fn as_arc_vec_f32(&self) -> Arc<Vec<f32>> {
match self {
ZapParam::ReadOnlyF32Buffer(v) => Arc::clone(v),
_ => panic!("{:?} is not a ReadOnlyF32Buffer", self),
}
}
pub fn into_string(self) -> String {
match self {
ZapParam::String(v) => v,
_ => panic!("ZapParam is not a String"),
}
}
pub fn into_vec_u8(self) -> Vec<u8> {
match self {
ZapParam::MutableU8Buffer(v) => v,
_ => panic!("{:?} is not a U8Buffer", self),
}
}
pub fn into_vec_f32(self) -> Vec<f32> {
match self {
ZapParam::MutableF32Buffer(v) => v,
_ => panic!("{:?} is not a F32Buffer", self),
}
}
}
pub trait IntoParam {
fn into_param(self) -> ZapParam;
}
impl IntoParam for String {
fn into_param(self) -> ZapParam {
ZapParam::String(self)
}
}
impl IntoParam for Vec<u8> {
fn into_param(self) -> ZapParam {
ZapParam::MutableU8Buffer(self)
}
}
impl IntoParam for Vec<f32> {
fn into_param(self) -> ZapParam {
ZapParam::MutableF32Buffer(self)
}
}
impl IntoParam for Arc<Vec<u8>> {
fn into_param(self) -> ZapParam {
ZapParam::ReadOnlyU8Buffer(self)
}
}
impl IntoParam for Arc<Vec<f32>> {
fn into_param(self) -> ZapParam {
ZapParam::ReadOnlyF32Buffer(self)
}
}