Crates.io | brainfuck-exe |
lib.rs | brainfuck-exe |
version | 0.2.4 |
source | src |
created_at | 2023-01-20 02:02:58.438053 |
updated_at | 2023-02-18 00:47:12.390518 |
description | A brainfuck interpreter implemented in rust |
homepage | |
repository | https://github.com/Tom-the-Bomb/brainfuck-rs |
max_upload_size | |
id | 763071 |
size | 58,915 |
a simple brainfuck
interpreter crate implemented in rust 🦀
with many available customizations for flexibility
For more information visit the documentation here
In your Cargo.toml
:
brainfuck-exe = "*"
If you are only using it as a library, and the CLI is not needed,
disable the cli
(included by default) feature to remove unecessary dependencies:
brainfuck-exe = { version = "*", default-features = false }
Below is a basic example on how to use the 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(())
}
You can also use this crate as a CLI program
# installation
$ cargo install brainfuck-exe
# usage
$ brainfuck --help
$ brainfuck [CODE] [-f FILE] [OPTIONS]