12 个版本
0.2.4 | 2023 年 2 月 18 日 |
---|---|
0.2.3 | 2023 年 2 月 14 日 |
0.1.8 | 2023 年 2 月 10 日 |
0.1.7 | 2023 年 1 月 30 日 |
296 在 编程语言 中排名
每月下载 38 次
32KB
526 行
Brainfuck-exe
一个简单的 brainfuck
解释器 crate,使用 Rust 实现 🦀,具有许多可用的自定义选项以增加灵活性
更多信息请访问文档 此处
用法
在你的 Cargo.toml
brainfuck-exe = "*"
如果你只将其用作库,并且不需要 CLI,
禁用 cli
(默认包含)功能以删除不必要的依赖项
brainfuck-exe = { version = "*", default-features = false }
示例
以下是如何使用此 crate 的基本示例
use std::fs::File;
// import Result typealias and interpreter struct
use brainfuck_exe::{Result, Brainfuck};
fn main() -> Result<()> {
// brainfuck code to print "Hello, World!"
let code = ">++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<+
+.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>-]<+.";
// instantiate a new interpreter instance with the code
Brainfuck::new(code)
// optional builder method to write the output into a file not STDOUT
.with_output(
File::options()
.write(true)
.open("tests/output.txt")
.unwrap()
)
// executes the code
.execute()?;
// alternatively use this to retrieve the code from an existing source file
Brainfuck::from_file("tests/hello_world.bf")?
.execute()?;
Ok(())
}
CLI
你还可以将此 crate 用作 CLI 程序
# installation
$ cargo install brainfuck-exe
# usage
$ brainfuck --help
$ brainfuck [CODE] [-f FILE] [OPTIONS]
依赖项
~0–280KB