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.
```rust use tugraph::{db::Graph, Result, txn::TxnRead}; use tugraphpluginutil::tugraph_plugin;
fn userprocessfunc(graph: &mut Graph, request: &str) -> Result
It exports a attribute proc-macro #[tugraph_plugin]
which can decorate a rust function and make the function expanded as:
```rust use tugraphpluginutil::lgraphapigraphdbt; use tugraphpluginutil::CxxString; use tugraphpluginutil::Graph as TuGraph;
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
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
}
}
} ```