3个版本
0.2.2 | 2023年2月25日 |
---|---|
0.2.1 | 2023年2月25日 |
0.2.0 | 2023年2月24日 |
703 / WebAssembly
9KB
70 行
wasi-print: : no_std WASI的Rust打印宏实现
Bart Massey 2023 (版本 0.2.2)
此crate包含为WASI编写no_std
模块的基本功能。wasi-print
提供
- 一个
abort()
函数,用于引发WASI异常。 - 一个在尝试打印panic信息后终止的
panic_handler
。 - 一个将
&str
打印到WASIfd
的print_fd()
函数。 - 打印宏
print!()
、println!()
、!eprint()
和!eprintln()
。
示例
这是一个使用wasi_print
的完整的独立Rust WASM程序。
#![no_std]
use wasi_print::*;
#[no_mangle]
pub extern "C" fn math_add(x: i32, y: i32) -> i32 {
eprint!("guest running math_add({}, {}) …", x, y);
let result = x + y;
eprintln!(" and returning {}", result);
result
}
功能
print
:包含打印代码。这需要nightly,原因有很多。panic_handler
:提供一个panic处理器。
致谢
通过阅读这篇优秀的博客文章,"James [Undefined]",编写这个程序变得更加容易。
许可证
此作品根据“MIT许可证”授权。请参阅此发行版中的LICENSE.txt
文件以获取许可证条款。
进一步致谢
感谢cargo-readme
crate为此README
的生成。
依赖
~0.5–8.5MB
~58K SLoC