12 releases

0.2.4 Feb 18, 2023
0.2.3 Feb 14, 2023
0.1.8 Feb 10, 2023
0.1.7 Jan 30, 2023

#437 in Programming languages

Download history 18/week @ 2024-07-20 96/week @ 2024-07-27 1/week @ 2024-08-03 3/week @ 2024-08-10 31/week @ 2024-08-24 4/week @ 2024-08-31 5/week @ 2024-09-14 6/week @ 2024-09-21 16/week @ 2024-09-28 20/week @ 2024-10-05 44/week @ 2024-10-12 3/week @ 2024-10-19 21/week @ 2024-11-02

70 downloads per month

MIT license

32KB
526 lines

Brainfuck-exe

a simple brainfuck interpreter crate implemented in rust 🦀 with many available customizations for flexibility
For more information visit the documentation here

Usage

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 }

Example

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(())
}

CLI

You can also use this crate as a CLI program

# installation
$ cargo install brainfuck-exe
# usage
$ brainfuck --help
$ brainfuck [CODE] [-f FILE] [OPTIONS]

Dependencies

~0–265KB