thomasmandorfer
thomasmandorfer6mo ago

Call Rust function from Deno API

I am new in deno. My question is what is the best way to call rust code in a deno api like oak? I tried it with https://napi.rs/ which did not work. Is there something similar for deno?
NAPI-RS
Home – NAPI-RS
NAPI-RS is a framework for building Node.js addons in Rust.
5 Replies
marvinh.
marvinh.6mo ago
There are two ways to call native code from within JavaScript running in Deno: 1. Compile native code to WASM and call that 2. Use FFI, see https://docs.deno.com/runtime/manual/runtime/ffi_api
Foreign Function Interface | Deno Docs
As of Deno 1.13 and later, the FFI (foreign function interface) API allows users
thomasmandorfer
thomasmandorfer6mo ago
thanks I will try it out I tried it out one question is threre a way send strings and return strings with deno ffi?
thomasmandorfer
thomasmandorfer6mo ago
No description
bartlomieju
bartlomieju6mo ago
Yes, strings are essentially buffers
marvinh.
marvinh.6mo ago
Yes, by encoding strings to a Uint8Array and decoding that with TextDecoder on the JS side