cleanup: add PTR as an alias for ValType::I64 (#558)

This will help simplify writing the types for host functions, `PTR` can
be used for any arguments that will point to Extism memory instead of
`ValType::I64`
This commit is contained in:
zach
2023-11-02 13:45:09 -07:00
committed by GitHub
parent c5b3af2963
commit ce5d43c9ae
3 changed files with 7 additions and 4 deletions

View File

@@ -174,14 +174,14 @@ fn main() {
.with_wasi(true)
.with_function(
"kv_read",
[ValType::I64],
[ValType::I64],
[PTR],
[PTR],
kv_store.clone(),
kv_read,
)
.with_function(
"kv_write",
[ValType::I64, ValType::I64],
[PTR, PTR],
[],
kv_store.clone(),
kv_write,

View File

@@ -25,6 +25,9 @@ pub enum ValType {
ExternRef,
}
/// A wrapper around `ValType::I64` to specify arguments that are pointers to memory blocks
pub const PTR: ValType = ValType::I64;
impl From<wasmtime::ValType> for ValType {
fn from(value: wasmtime::ValType) -> Self {
use wasmtime::ValType::*;

View File

@@ -21,7 +21,7 @@ pub mod sdk;
pub use current_plugin::CurrentPlugin;
pub use extism_convert::{FromBytes, FromBytesOwned, ToBytes};
pub use extism_manifest::{Manifest, Wasm};
pub use function::{Function, UserData, Val, ValType};
pub use function::{Function, UserData, Val, ValType, PTR};
pub use plugin::{CancelHandle, Plugin, EXTISM_ENV_MODULE, EXTISM_USER_MODULE};
pub use plugin_builder::PluginBuilder;