A lightweight utility library for converting between C‐style null-terminated
byte strings (Bytes
) and MoonBit String
values.
- from_cstr: Convert a null-terminated
Bytes
to a MoonBitString
(drops the\x00
terminator). - to_cstr: Convert a MoonBit
String
to null-terminatedBytes
.
Add justjavac/ffi
to your dependencies:
moon update
moon add justjavac/ffi
// Convert Bytes → String
let data = b"Hello, world!\x00"
let s = @ffi.from_cstr(data)
assert_eq!(s, "Hello, world!")
// Convert String → Bytes
let cstr = @ffi.to_cstr("Hello, world!")
assert_eq!(cstr, data)
- Wasm & WasmGC
- JavaScript
- Native
- LLVM
Build the library and run tests (including docs):
moon build
moon test --doc
This project is licensed under the MIT License.
© justjavac