rsmgp_sys/lib.rs
1// Copyright (c) 2016-2021 Memgraph Ltd. [https://memgraph.com]
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//! A library to simplify implementation of Memgraph Query Modules.
15//!
16//! Example
17//!
18//! ```
19//! use c_str_macro::c_str;
20//! // All possible rsmgp modules (probably not all will be required).
21//! use rsmgp_sys::edge::*;
22//! use rsmgp_sys::list::*;
23//! use rsmgp_sys::map::*;
24//! use rsmgp_sys::memgraph::*;
25//! use rsmgp_sys::mgp::*;
26//! use rsmgp_sys::path::*;
27//! use rsmgp_sys::property::*;
28//! use rsmgp_sys::result::*;
29//! use rsmgp_sys::rsmgp::*;
30//! use rsmgp_sys::value::*;
31//! use rsmgp_sys::vertex::*;
32//! use rsmgp_sys::{close_module, define_procedure, define_type, init_module};
33//! // The following are required because of used macros.
34//! use std::ffi::CString;
35//! use std::os::raw::c_int;
36//! use std::panic;
37//!
38//! init_module!(|memgraph: &Memgraph| -> MgpResult<()> {
39//! memgraph.add_read_procedure(
40//! basic, // Has to be the same as specified in the `define_procedure!`.
41//! c_str!("basic"), // Name under which Memgraph will register the procedure.
42//! &[define_type!("input_string", Type::String)], // Required arguments.
43//! &[], // Optional arguments.
44//! &[define_type!("output_string", Type::String)], // Return fields.
45//! )?;
46//! Ok(())
47//! });
48//!
49//! define_procedure!(basic, |memgraph: &Memgraph| -> MgpResult<()> {
50//! let result = memgraph.result_record()?;
51//! let args = memgraph.args()?;
52//! let output_string = args.value_at(0)?;
53//! result.insert_mgp_value(
54//! c_str!("output_string"),
55//! &output_string.to_mgp_value(&memgraph)?,
56//! )?;
57//! Ok(())
58//! });
59//!
60//! close_module!(|| -> MgpResult<()> { Ok(()) });
61//! ```
62
63#[cfg(test)]
64extern crate mockall;
65
66extern crate mockall_double;
67
68mod testing;
69
70pub mod edge;
71pub mod list;
72pub mod map;
73pub mod memgraph;
74pub mod mgp;
75pub mod path;
76pub mod property;
77pub mod result;
78pub mod rsmgp;
79pub mod value;
80pub mod vertex;