Crate databind[][src]

Expand description

Expand the functionality of Minecraft Datapacks.


If you’re just looking to use Databind as a tool and not to make your own Rust project with it, then you can use the CLI. Documentation for it is available here.

Quick Start

Here’s some code to compile a given string and print the output for each file:

use databind::compiler::Compiler;
use std::collections::HashMap;

// Source file
let source_file = "
func main\n\
    say Hello, World!\n\
func second_func\n\
    say Second function\n\
// Create compiler and tokenize source file
let mut compiler = Compiler::new(source_file, None);
let tokens = compiler.tokenize();
// Compile tokens to files
let compiled = compiler.compile(tokens, None, "", &HashMap::new(), false);
// Print the contents of each file
for (k, v) in compiled.filename_map.iter() {
    println!("Output File: {}.mcfunction", k);
    println!("Contents:\n{}", compiled.file_contents[*v]);

The code above results in the following output:

Output File: main.mcfunction
say Hello, World!
Output File: second_func.mcfunction
say Second function


Contains functions and structs used to tokenize and compile Databind source code

Contains functions used by the CLI to get information from files or to create files

Contains type definitions used throughout the project


Settings for the compiler


The enum of Databind tokens used for tokenization of Databind source files