tugraph-plugin-util is a helper crate which make any rust function with following signature rust fn (_: &mut Graph, _: &str) -> Result<String> to be a plugin entry point.

Example

```rust use tugraph::{db::Graph, Result, txn::TxnRead}; use pluginutil::tugraphplugin;

[tugraph_plugin]

fn userprocessfunc(graph: &mut Graph, request: &str) -> Result { // user process code Ok("Process Result".to_string()) } ```

It exports a attribute proc-macro #[tugraph_plugin] which can decorate a rust function and make the function expanded as:

```rust use pluginutil::lgraphapigraphdbt; use pluginutil::CxxString; use plugin_util::Graph as TuGraph;

[no_mangle]

pub unsafe extern "C" fn Process( graphdb: *mut lgraphapigraphdbt, request: *const CxxString, response: *mut CxxString) -> bool { let mut graph = TuGraph::fromptr(graphdb); let request = if request.isnull() { "" } else { (*request).tostr().unwrap() }; // user defined process function are nested here fn userprocessfunc(graph: &mut Graph, request: &str) -> Result { // ... } let result = userprocess_func(&mut graph, request); ::std::mem::forget(graph);

match result {
    Ok(val) => {
        if !response.is_null() {
            let mut reponse = ::std::pin::Pin::new_unchecked(&mut *response);
            reponse.as_mut().clear();
            reponse.as_mut().push_str(val.as_str())
        }
        true
    }
    Err(e) => {
        eprintln!("run rust plugin failed: {:?}", e);
        false
    }
}

} ```