[][src]Function tcpp::process_with

pub fn process_with<T, F>(data: String, error: T, include: F) -> Option<String> where
    T: FnMut(TErrorInfo),
    F: FnMut(String, bool) -> IInputStream

This function calls the tcpp preprocessor with two callback functions.

While performs the same as function process, this functions accepts two closures to handle errors and inclusion (i.e. #include) respectively. which gives more flexibility and supports further multi-file processing

Example

use tcpp::*;
use tcpp::ffi::*;

fn main() {
    // read content from source file
    let content = String::from_utf8(std::fs::read("main.c").unwrap()).unwrap();
    let result = process_with(content,
        |error| { // error processor
            panic!("Preprocessor error: {} at line {}"
                    , error.get_message().unwrap() // get description of the error
                    , error.get_line()); // get line number of the error
        },
        |_, _|  { // inclusion processor
            // we just ignore inclusions and returns a default (null) stream
            IInputStream::default()
        });
}