Query modules Rust API
This is the API documentation for the Rust binding of Memgraph’s C API, which contains declarations of all
functions for implementing query module procedures and functions.
The source files can be found in the Memgraph MAGE file structure (in the memgraph-mage-dev Docker images,
they can be found under /mage/rust). On Github, it can be found
under the rust file structure.
To see how to implement query modules in C++, take a look at the example we provided.
Functions and procedures
Memgraph Procedure API
Memgraph
new
Creates a new Memgraph object.
pub fn new(
args: *mut mgp_list,
graph: *mut mgp_graph,
result: *mut mgp_result,
memory: *mut mgp_memory,
module: *mut mgp_module
) -> Memgraph- Parameters:
args: A pointer tomgp_list.graph: A pointer tomgp_graph.result: A pointer tomgp_result.memory: A pointer tomgp_memory.module: A pointer tomgp_module.
- Returns: A new instance of
Memgraph.
new_default
Creates a new Memgraph object with all underlying data set to null. Used for testing purposes.
#[cfg(test)]
pub(crate) fn new_default() -> Memgraph- Returns: A new instance of
Memgraphwith default values.
args
Returns the arguments passed to the procedure call.
pub fn args(&self) -> Result<List>- Returns: A
Resultcontaining theListof arguments if successful.
args_ptr
Returns a pointer to the object with all arguments passed to the procedure call.
pub(crate) fn args_ptr(&self) -> *mut mgp_list- Returns: A pointer to
mgp_list.
graph_ptr
Returns a pointer to the object with graph data.
pub(crate) fn graph_ptr(&self) -> *mut mgp_graph- Returns: A pointer to
mgp_graph.
result_ptr
Returns a pointer to the object where results could be stored.
pub(crate) fn result_ptr(&self) -> *mut mgp_result- Returns: A pointer to
mgp_result.
memory_ptr
Returns a pointer to the memory object for advanced memory control.
pub(crate) fn memory_ptr(&self) -> *mut mgp_memory- Returns: A pointer to
mgp_memory.
module_ptr
Returns a pointer to the module object.
pub fn module_ptr(&self) -> *mut mgp_module- Returns: A pointer to
mgp_module.
vertices_iter
Returns an iterator over the vertices in the graph.
pub fn vertices_iter(&self) -> Result<VerticesIterator>- Returns: A
Resultcontaining aVerticesIteratorif successful.
vertex_by_id
Returns a vertex with the given ID.
pub fn vertex_by_id(&self, id: i64) -> Result<Vertex>- Parameters:
id: The ID of the vertex to retrieve.
- Returns: A
Resultcontaining theVertexif successful.
result_record
Creates a new result record.
pub fn result_record(&self) -> Result<ResultRecord>- Returns: A
Resultcontaining a newResultRecordif successful.
add_read_procedure
Registers a new read procedure.
pub fn add_read_procedure(
&self,
proc_ptr: extern "C" fn(*mut mgp_list, *mut mgp_graph, *mut mgp_result, *mut mgp_memory),
name: &CStr,
required_arg_types: &[NamedType],
optional_arg_types: &[OptionalNamedType],
result_field_types: &[NamedType]
) -> Result<()>- Parameters:
proc_ptr: Identifier of the top-level C function that represents the procedure.name: A string that will be registered as a procedure name inside the Memgraph instance.required_arg_types: An array of allNamedTypes, each one defined by name and an array ofTypes.optional_arg_types: An array of allOptionalNamedTypes, each one defined by name, an array ofTypes, and default value.result_field_types: An array of allNamedTypes, each one defined by name and an array ofTypes.
- Returns: A
Resultindicating success or failure.
must_abort
Returns true if the currently executing procedure should abort as soon as possible.
pub fn must_abort(&self) -> bool- Returns:
trueif the procedure should abort,falseotherwise.
MgpError
Defines various errors that can occur in the API.
#[derive(Debug, PartialEq)]
pub enum MgpError {
UnknownError,
UnableToAllocate,
InsufficientError,
OutOfRange,
LogicError,
DeletedObject,
InvalidArgument,
KeyAlreadyExists,
ImmutableObject,
ValueConversion,
SerializationError,
}MgpDefault
A trait to define default values for various types.
pub(crate) trait MgpDefault {
fn default() -> Self;
}to_rust_mgp_error
Converts a mgp_error to an MgpError.
pub(crate) fn to_rust_mgp_error(error: mgp_error) -> Option<MgpError>- Parameters:
error: Amgp_error.
- Returns: An
Optioncontaining anMgpErrorif the error is notMGP_ERROR_NO_ERROR.
invoke_mgp_func
A macro to invoke a Memgraph function and handle the result.
macro_rules! invoke_mgp_func {
($result_type:ty, $func:expr) => {{ ... }};
($result_type:ty, $func:expr, $($args:expr),+) => {{ ... }};
}invoke_void_mgp_func
A macro to invoke a Memgraph function that returns void and handle the result.
macro_rules! invoke_void_mgp_func {
($func:expr, $($args:expr),+) => {{ ... }};
}invoke_mgp_func_with_res
A macro to invoke a Memgraph function and map the result to a custom error.
macro_rules! invoke_mgp_func_with_res {
($result_type:ty, $err:expr, $func:expr) => {{ ... }};
($result_type:ty, $err:expr, $func:expr, $($args:expr),+) => {{ ... }};
}invoke_void_mgp_func_with_res
A macro to invoke a Memgraph function that returns void and map the result to a custom error.
macro_rules! invoke_void_mgp_func_with_res {
($err:expr, $func:expr, $($args:expr),+) => {{ ... }};
}resolve_mgp_type
Combines the given array of types from left to right to construct mgp_type.
fn resolve_mgp_type(types: &[Type]) -> *mut mgp_type- Parameters:
types: A slice ofTypes.
- Returns: A pointer to the constructed
mgp_type.
Graph API
VerticesIterator
new
Creates a new VerticesIterator.
pub(crate) fn new(ptr: *mut mgp_vertices_iterator, memgraph: &Memgraph) -> VerticesIterator- Parameters:
ptr: A pointer tomgp_vertices_iterator.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
VerticesIterator.
next
Returns the next vertex in the iteration.
fn next(&mut self) -> Option<Vertex>- Returns: An
Optioncontaining the nextVertexif available, otherwiseNone.
Drop
Drops the VerticesIterator and releases the associated resources.
fn drop(&mut self)Vertex
new
Creates a new Vertex.
pub(crate) fn new(ptr: *mut mgp_vertex, memgraph: &Memgraph) -> Vertex- Parameters:
ptr: A pointer tomgp_vertex.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
Vertex.
mgp_copy
Creates a new Vertex based on an mgp_vertex.
pub(crate) unsafe fn mgp_copy(mgp_vertex: *mut mgp_vertex, memgraph: &Memgraph) -> Result<Vertex>- Parameters:
mgp_vertex: A pointer tomgp_vertex.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newVertexinstance if successful.
mgp_ptr
Returns the underlying mgp_vertex pointer.
pub(crate) fn mgp_ptr(&self) -> *mut mgp_vertex- Returns: A pointer to
mgp_vertex.
set_mgp_ptr
Sets a new mgp_vertex pointer.
pub(crate) fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_vertex)- Parameters:
new_ptr: A new pointer tomgp_vertex.
id
Returns the ID of the Vertex.
pub fn id(&self) -> i64- Returns: The ID of the
Vertex.
labels_count
Returns the number of labels associated with the Vertex.
pub fn labels_count(&self) -> Result<u64>- Returns: A
Resultcontaining the number of labels asu64if successful.
label_at
Returns the label at the specified index.
pub fn label_at(&self, index: u64) -> Result<CString>- Parameters:
index: The index of the label.
- Returns: A
Resultcontaining the label as aCStringif successful.
has_label
Checks if the Vertex has the specified label.
pub fn has_label(&self, name: &CStr) -> Result<bool>- Parameters:
name: The name of the label as aCStr.
- Returns: A
Resultcontainingtrueif theVertexhas the label, otherwisefalse.
property
Returns the value of a property of the Vertex.
pub fn property(&self, name: &CStr) -> Result<Property>- Parameters:
name: The name of the property as aCStr.
- Returns: A
Resultcontaining thePropertyif successful.
properties
Returns an iterator over the properties of the Vertex.
pub fn properties(&self) -> Result<PropertiesIterator>- Returns: A
Resultcontaining aPropertiesIteratorif successful.
in_edges
Returns an iterator over the incoming edges of the Vertex.
pub fn in_edges(&self) -> Result<EdgesIterator>- Returns: A
Resultcontaining anEdgesIteratorif successful.
out_edges
Returns an iterator over the outgoing edges of the Vertex.
pub fn out_edges(&self) -> Result<EdgesIterator>- Returns: A
Resultcontaining anEdgesIteratorif successful.
Drop
Drops the Vertex and releases the associated resources.
fn drop(&mut self)EdgesIterator
new
Creates a new EdgesIterator.
pub(crate) fn new(ptr: *mut mgp_edges_iterator, memgraph: &Memgraph) -> EdgesIterator- Parameters:
ptr: A pointer tomgp_edges_iterator.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
EdgesIterator.
next
Returns the next edge in the iteration.
fn next(&mut self) -> Option<Edge>- Returns: An
Optioncontaining the nextEdgeif available, otherwiseNone.
Drop
Drops the EdgesIterator and releases the associated resources.
fn drop(&mut self)Edge
new
Creates a new Edge.
pub(crate) fn new(ptr: *mut mgp_edge, memgraph: &Memgraph) -> Edge- Parameters:
ptr: A pointer tomgp_edge.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
Edge.
mgp_copy
Creates a new Edge based on an mgp_edge.
pub(crate) unsafe fn mgp_copy(ptr: *mut mgp_edge, memgraph: &Memgraph) -> Result<Edge>- Parameters:
ptr: A pointer tomgp_edge.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newEdgeinstance if successful.
mgp_ptr
Returns the underlying mgp_edge pointer.
pub(crate) fn mgp_ptr(&self) -> *mut mgp_edge- Returns: A pointer to
mgp_edge.
set_mgp_ptr
Sets a new mgp_edge pointer.
pub(crate) fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_edge)- Parameters:
new_ptr: A new pointer tomgp_edge.
copy
Creates a copy of the Edge.
pub fn copy(&self) -> Result<Edge>- Returns: A
Resultcontaining the copiedEdgeif successful.
id
Returns the ID of the Edge.
pub fn id(&self) -> i64- Returns: The ID of the
Edge.
edge_type
Returns the type of the Edge.
pub fn edge_type(&self) -> Result<CString>- Returns: A
Resultcontaining the type of theEdgeas aCStringif successful.
from_vertex
Returns the vertex from which the Edge originates.
pub fn from_vertex(&self) -> Result<Vertex>- Returns: A
Resultcontaining the originatingVertexif successful.
to_vertex
Returns the vertex to which the Edge points.
pub fn to_vertex(&self) -> Result<Vertex>- Returns: A
Resultcontaining the destinationVertexif successful.
property
Returns the value of a property of the Edge.
pub fn property(&self, name: &CStr) -> Result<Property>- Parameters:
name: The name of the property as aCStr.
- Returns: A
Resultcontaining thePropertyif successful.
properties
Returns an iterator over the properties of the Edge.
pub fn properties(&self) -> Result<PropertiesIterator>- Returns: A
Resultcontaining aPropertiesIteratorif successful.
Drop
Drops the Edge and releases the associated resources.
fn drop(&mut self)List
new
Creates a new List.
pub(crate) fn new(ptr: *mut mgp_list, memgraph: &Memgraph) -> List- Parameters:
ptr: A pointer tomgp_list.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
List.
make_empty
Creates an empty List with the specified capacity.
pub fn make_empty(capacity: u64, memgraph: &Memgraph) -> Result<List>- Parameters:
capacity: The initial capacity of the list.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newListif successful.
mgp_copy
Creates a copy of an existing List.
pub(crate) unsafe fn mgp_copy(ptr: *mut mgp_list, memgraph: &Memgraph) -> Result<List>- Parameters:
ptr: A pointer tomgp_list.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a copiedListif successful.
copy
Creates a copy of the current List.
pub fn copy(&self) -> Result<List>- Returns: A
Resultcontaining the copiedListif successful.
append
Appends a value to the List. Returns an error if there is no space.
pub fn append(&self, value: &Value) -> Result<()>- Parameters:
value: TheValueto append.
- Returns: A
Resultindicating success or failure.
append_extend
Appends a value to the List, extending the capacity if necessary.
pub fn append_extend(&self, value: &Value) -> Result<()>- Parameters:
value: TheValueto append.
- Returns: A
Resultindicating success or failure.
size
Returns the size of the List.
pub fn size(&self) -> u64- Returns: The size of the
List.
capacity
Returns the capacity of the List.
pub fn capacity(&self) -> u64- Returns: The capacity of the
List.
value_at
Returns the value at the specified index.
pub fn value_at(&self, index: u64) -> Result<Value>- Parameters:
index: The index of the value to retrieve.
- Returns: A
Resultcontaining theValueif successful.
iter
Returns an iterator over the List.
pub fn iter(&self) -> Result<ListIterator>- Returns: A
Resultcontaining aListIteratorif successful.
mgp_ptr
Returns the underlying mgp_list pointer.
pub(crate) fn mgp_ptr(&self) -> *mut mgp_list- Returns: A pointer to
mgp_list.
set_mgp_ptr
Sets a new mgp_list pointer.
pub(crate) fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_list)- Parameters:
new_ptr: A new pointer tomgp_list.
Drop
Drops the List and releases the associated resources.
fn drop(&mut self)ListIterator
next
Returns the next value in the iteration.
fn next(&mut self) -> Option<Value>- Returns: An
Optioncontaining the nextValueif available, otherwiseNone.
Map
new
Creates a new Map.
pub(crate) fn new(ptr: *mut mgp_map, memgraph: &Memgraph) -> Map- Parameters:
ptr: A pointer tomgp_map.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
Map.
mgp_copy
Creates a copy of an existing Map.
pub(crate) unsafe fn mgp_copy(ptr: *mut mgp_map, memgraph: &Memgraph) -> Result<Map>- Parameters:
ptr: A pointer tomgp_map.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a copiedMapif successful.
make_empty
Creates an empty Map.
pub fn make_empty(memgraph: &Memgraph) -> Result<Map>- Parameters:
memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a new emptyMapif successful.
insert
Inserts a key-value pair into the Map.
pub fn insert(&self, key: &CStr, value: &Value) -> Result<()>- Parameters:
key: The key as aCStr.value: The value to insert.
- Returns: A
Resultindicating success or failure.
size
Returns the size of the Map.
pub fn size(&self) -> u64- Returns: The size of the
Map.
at
Returns the value associated with the specified key.
pub fn at(&self, key: &CStr) -> Result<Value>- Parameters:
key: The key as aCStr.
- Returns: A
Resultcontaining theValueif successful.
iter
Returns an iterator over the Map.
pub fn iter(&self) -> Result<MapIterator>- Returns: A
Resultcontaining aMapIteratorif successful.
mgp_ptr
Returns the underlying mgp_map pointer.
pub(crate) fn mgp_ptr(&self) -> *mut mgp_map- Returns: A pointer to
mgp_map.
set_mgp_ptr
Sets a new mgp_map pointer.
pub(crate) fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_map)- Parameters:
new_ptr: A new pointer tomgp_map.
Drop
Drops the Map and releases the associated resources.
fn drop(&mut self)MapItem
Fields
Represents an item in the Map with a key-value pair.
- key: The key as a
CString. - value: The value as a
Value.
pub struct MapItem {
pub key: CString,
pub value: Value,
}MapIterator
new
Creates a new MapIterator.
pub(crate) fn new(ptr: *mut mgp_map_items_iterator, memgraph: &Memgraph) -> MapIterator- Parameters:
ptr: A pointer tomgp_map_items_iterator.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
MapIterator.
next
Returns the next item in the iteration.
fn next(&mut self) -> Option<MapItem>- Returns: An
Optioncontaining the nextMapItemif available, otherwiseNone.
Drop
Drops the MapIterator and releases the associated resources.
fn drop(&mut self)MgpValue
new
Creates a new MgpValue.
pub(crate) fn new(ptr: *mut mgp_value, memgraph: &Memgraph) -> MgpValue- Parameters:
ptr: A pointer tomgp_value.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
MgpValue.
mgp_ptr
Returns the underlying mgp_value pointer.
pub(crate) fn mgp_ptr(&self) -> *mut mgp_value- Returns: A pointer to
mgp_value.
to_value
Converts the MgpValue to a Value.
pub fn to_value(&self) -> Result<Value>- Returns: A
Resultcontaining theValueif successful.
make_null
Creates a MgpValue representing a null value.
pub fn make_null(memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_null
Checks if the MgpValue is null.
pub fn is_null(&self) -> bool- Returns:
trueif theMgpValueis null, otherwisefalse.
make_bool
Creates a MgpValue representing a boolean value.
pub fn make_bool(value: bool, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
value: The boolean value.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_bool
Checks if the MgpValue is a boolean.
pub fn is_bool(&self) -> bool- Returns:
trueif theMgpValueis a boolean, otherwisefalse.
make_int
Creates a MgpValue representing an integer value.
pub fn make_int(value: i64, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
value: The integer value.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_int
Checks if the MgpValue is an integer.
pub fn is_int(&self) -> bool- Returns:
trueif theMgpValueis an integer, otherwisefalse.
make_double
Creates a MgpValue representing a double value.
pub fn make_double(value: f64, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
value: The double value.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_double
Checks if the MgpValue is a double.
pub fn is_double(&self) -> bool- Returns:
trueif theMgpValueis a double, otherwisefalse.
make_string
Creates a MgpValue representing a string value.
pub fn make_string(value: &CStr, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
value: The string value as aCStr.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_string
Checks if the MgpValue is a string.
pub fn is_string(&self) -> bool- Returns:
trueif theMgpValueis a string, otherwisefalse.
make_list
Creates a MgpValue representing a list value.
pub fn make_list(list: &List, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
list: TheListto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_list
Checks if the MgpValue is a list.
pub fn is_list(&self) -> bool- Returns:
trueif theMgpValueis a list, otherwisefalse.
make_map
Creates a MgpValue representing a map value.
pub fn make_map(map: &Map, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
map: TheMapto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_map
Checks if the MgpValue is a map.
pub fn is_map(&self) -> bool- Returns:
trueif theMgpValueis a map, otherwisefalse.
make_vertex
Creates a MgpValue representing a vertex value.
pub fn make_vertex(vertex: &Vertex, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
vertex: TheVertexto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_vertex
Checks if the MgpValue is a vertex.
pub fn is_vertex(&self) -> bool- Returns:
trueif theMgpValueis a vertex, otherwisefalse.
make_edge
Creates a MgpValue representing an edge value.
pub fn make_edge(edge: &Edge, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
edge: TheEdgeto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_edge
Checks if the MgpValue is an edge.
pub fn is_edge(&self) -> bool- Returns:
trueif theMgpValueis an edge, otherwisefalse.
make_path
Creates a MgpValue representing a path value.
pub fn make_path(path: &Path, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
path: ThePathto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_path
Checks if the MgpValue is a path.
pub fn is_path(&self) -> bool- Returns:
trueif theMgpValueis a path, otherwisefalse.
make_date
Creates a MgpValue representing a date value.
pub fn make_date(date: &NaiveDate, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
date: TheNaiveDateto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_date
Checks if the MgpValue is a date.
pub fn is_date(&self) -> bool- Returns:
trueif theMgpValueis a date, otherwisefalse.
make_local_time
Creates a MgpValue representing a local time value.
pub fn make_local_time(time: &NaiveTime, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
time: TheNaiveTimeto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_local_time
Checks if the MgpValue is a local time.
pub fn is_local_time(&self) -> bool- Returns:
trueif theMgpValueis a local time, otherwisefalse.
make_local_date_time
Creates a MgpValue representing a local date-time value.
pub fn make_local_date_time(datetime: &NaiveDateTime
, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
datetime: TheNaiveDateTimeto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_local_date_time
Checks if the MgpValue is a local date-time.
pub fn is_local_date_time(&self) -> bool- Returns:
trueif theMgpValueis a local date-time, otherwisefalse.
make_duration
Creates a MgpValue representing a duration value.
pub fn make_duration(duration: &chrono::Duration, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
duration: TheDurationto be converted.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newMgpValueif successful.
is_duration
Checks if the MgpValue is a duration.
pub fn is_duration(&self) -> bool- Returns:
trueif theMgpValueis a duration, otherwisefalse.
Drop
Drops the MgpValue and releases the associated resources.
fn drop(&mut self)Path
new
Creates a new Path.
pub(crate) fn new(ptr: *mut mgp_path, memgraph: &Memgraph) -> Path- Parameters:
ptr: A pointer tomgp_path.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
Path.
mgp_copy
Creates a copy of an existing Path.
pub(crate) unsafe fn mgp_copy(mgp_path: *mut mgp_path, memgraph: &Memgraph) -> Result<Path>- Parameters:
mgp_path: A pointer tomgp_path.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a copiedPathif successful.
mgp_ptr
Returns the underlying mgp_path pointer.
pub(crate) fn mgp_ptr(&self) -> *mut mgp_path- Returns: A pointer to
mgp_path.
set_mgp_ptr
Sets a new mgp_path pointer.
pub(crate) fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_path)- Parameters:
new_ptr: A new pointer tomgp_path.
size
Returns the size of the Path.
pub fn size(&self) -> u64- Returns: The size of the
Path.
make_with_start
Creates a new Path starting with the specified Vertex.
pub fn make_with_start(vertex: &Vertex, memgraph: &Memgraph) -> Result<Path>- Parameters:
vertex: The startingVertex.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newPathif successful.
expand
Expands the Path by adding an Edge. Fails if the current last vertex in the path is not part of the given edge or if there is no memory to expand the path.
pub fn expand(&self, edge: &Edge) -> Result<()>- Parameters:
edge: TheEdgeto add.
- Returns: A
Resultindicating success or failure.
vertex_at
Returns the Vertex at the specified index.
pub fn vertex_at(&self, index: u64) -> Result<Vertex>- Parameters:
index: The index of theVertexto retrieve.
- Returns: A
Resultcontaining theVertexif successful.
edge_at
Returns the Edge at the specified index.
pub fn edge_at(&self, index: u64) -> Result<Edge>- Parameters:
index: The index of theEdgeto retrieve.
- Returns: A
Resultcontaining theEdgeif successful.
Drop
Drops the Path and releases the associated resources.
fn drop(&mut self)Property
Represents a property with a name and value.
pub struct Property {
pub name: CString,
pub value: Value,
}- Fields:
name: The name of the property as aCString.value: The value of the property as aValue.
PropertiesIterator
new
Creates a new PropertiesIterator.
pub(crate) fn new(ptr: *mut mgp_properties_iterator, memgraph: &Memgraph) -> PropertiesIterator- Parameters:
ptr: A pointer tomgp_properties_iterator.memgraph: A reference to aMemgraphinstance.
- Returns: A new instance of
PropertiesIterator.
next
Returns the next property in the iteration.
fn next(&mut self) -> Option<Property>- Returns: An
Optioncontaining the nextPropertyif available, otherwiseNone.
Drop
Drops the PropertiesIterator and releases the associated resources.
fn drop(&mut self)ResultRecord
create
Creates a new ResultRecord.
pub fn create(memgraph: &Memgraph) -> Result<ResultRecord>- Parameters:
memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newResultRecordif successful.
insert_mgp_value
Inserts an MgpValue into the ResultRecord.
pub fn insert_mgp_value(&self, field: &CStr, value: &MgpValue) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheMgpValueto insert.
- Returns: A
Resultindicating success or failure.
insert_null
Inserts a null value into the ResultRecord.
pub fn insert_null(&self, field: &CStr) -> Result<()>- Parameters:
field: The field name as aCStr.
- Returns: A
Resultindicating success or failure.
insert_bool
Inserts a boolean value into the ResultRecord.
pub fn insert_bool(&self, field: &CStr, value: bool) -> Result<()>- Parameters:
field: The field name as aCStr.value: The boolean value to insert.
- Returns: A
Resultindicating success or failure.
insert_int
Inserts an integer value into the ResultRecord.
pub fn insert_int(&self, field: &CStr, value: i64) -> Result<()>- Parameters:
field: The field name as aCStr.value: The integer value to insert.
- Returns: A
Resultindicating success or failure.
insert_double
Inserts a double value into the ResultRecord.
pub fn insert_double(&self, field: &CStr, value: f64) -> Result<()>- Parameters:
field: The field name as aCStr.value: The double value to insert.
- Returns: A
Resultindicating success or failure.
insert_string
Inserts a string value into the ResultRecord.
pub fn insert_string(&self, field: &CStr, value: &CStr) -> Result<()>- Parameters:
field: The field name as aCStr.value: The string value as aCStrto insert.
- Returns: A
Resultindicating success or failure.
insert_list
Inserts a list value into the ResultRecord.
pub fn insert_list(&self, field: &CStr, value: &List) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheListto insert.
- Returns: A
Resultindicating success or failure.
insert_map
Inserts a map value into the ResultRecord.
pub fn insert_map(&self, field: &CStr, value: &Map) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheMapto insert.
- Returns: A
Resultindicating success or failure.
insert_vertex
Inserts a vertex value into the ResultRecord.
pub fn insert_vertex(&self, field: &CStr, value: &Vertex) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheVertexto insert.
- Returns: A
Resultindicating success or failure.
insert_edge
Inserts an edge value into the ResultRecord.
pub fn insert_edge(&self, field: &CStr, value: &Edge) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheEdgeto insert.
- Returns: A
Resultindicating success or failure.
insert_path
Inserts a path value into the ResultRecord.
pub fn insert_path(&self, field: &CStr, value: &Path) -> Result<()>- Parameters:
field: The field name as aCStr.value: ThePathto insert.
- Returns: A
Resultindicating success or failure.
insert_date
Inserts a date value into the ResultRecord.
pub fn insert_date(&self, field: &CStr, value: &NaiveDate) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheNaiveDateto insert.
- Returns: A
Resultindicating success or failure.
insert_local_time
Inserts a local time value into the ResultRecord.
pub fn insert_local_time(&self, field: &CStr, value: &NaiveTime) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheNaiveTimeto insert.
- Returns: A
Resultindicating success or failure.
insert_local_date_time
Inserts a local date-time value into the ResultRecord.
pub fn insert_local_date_time(&self, field: &CStr, value: &NaiveDateTime) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheNaiveDateTimeto insert.
- Returns: A
Resultindicating success or failure.
insert_duration
Inserts a duration value into the ResultRecord.
pub fn insert_duration(&self, field: &CStr, value: &chrono::Duration) -> Result<()>- Parameters:
field: The field name as aCStr.value: TheDurationto insert.
- Returns: A
Resultindicating success or failure.
Error
Defines various errors that can occur in the API.
#[derive(Debug, PartialEq, Snafu)]
#[snafu(visibility = "pub")]
pub enum Error {
UnableToCreateDateFromNaiveDate,
UnableToCreateDurationFromChronoDuration,
UnableToCopyEdge,
UnableToReturnEdgePropertyValueAllocationError,
UnableToReturnEdgePropertyValueCreationError,
UnableToReturnEdgePropertyNameAllocationError,
UnableToReturnEdgePropertyDeletedObjectError,
UnableToReturnEdgePropertiesIterator,
UnableToCreateEmptyList,
UnableToCopyList,
UnableToAppendListValue,
UnableToAppendExtendListValue,
UnableToAccessListValueByIndex,
UnableToCreateLocalTimeFromNaiveTime,
UnableToCreateLocalDateTimeFromNaiveDateTime,
UnableToCopyMap,
UnableToCreateEmptyMap,
UnableToInsertMapValue,
UnableToAccessMapValue,
UnableToCreateMapIterator,
UnableToCreateGraphVerticesIterator,
UnableToFindVertexById,
UnableToRegisterReadProcedure,
UnableToAddRequiredArguments,
UnableToAddOptionalArguments,
UnableToAddReturnType,
UnableToAddDeprecatedReturnType,
UnableToCopyPath,
OutOfBoundPathVertexIndex,
OutOfBoundPathEdgeIndex,
UnableToCreatePathWithStartVertex,
UnableToExpandPath,
UnableToCreateResultRecord,
UnableToInsertResultValue,
UnableToCreateCString,
UnableToMakeNullValue,
UnableToMakeBoolValue,
UnableToMakeIntegerValue,
UnableToMakeDoubleValue,
UnableToMakeMemgraphStringValue,
UnableToMakeListValue,
UnableToMakeMapValue,
UnableToMakeVertexValue,
UnableToMakeEdgeValue,
UnableToMakePathValue,
UnableToMakeValueString,
UnableToMakeDateValue,
UnableToMakeLocalTimeValue,
UnableToMakeLocalDateTimeValue,
UnableToMakeDurationValue,
UnableToCopyVertex,
OutOfBoundLabelIndexError,
UnableToGetVertexProperty,
UnableToReturnVertexPropertyMakeNameEror,
UnableToReturnVertexPropertiesIterator,
UnableToReturnVertexInEdgesIterator,
UnableToReturnVertexOutEdgesIterator,
UnableToReturnVertexLabelsCountDeletedObjectError,
UnableToReturnVertexLabelDeletedObjectError,
UnableToCheckVertexHasLabel,
}Result
Defines a result type holding Error by default.
pub type Result<T, E = Error> = std::result::Result<T, E>;- T: The type of the success value.
- E: The type of the error value (default is
Error).
Date
new
Creates a new Date.
pub(crate) fn new(ptr: *mut mgp_date) -> Date- Parameters:
ptr: A pointer tomgp_date.
- Returns: A new instance of
Date.
from_naive_date
Creates a Date from a NaiveDate.
pub fn from_naive_date(from: &NaiveDate, memgraph: &Memgraph) -> Result<Date>- Parameters:
from: A reference to aNaiveDate.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newDateif successful.
to_naive_date
Converts the Date to a NaiveDate.
pub fn to_naive_date(&self) -> NaiveDate- Returns: A
NaiveDaterepresenting theDate.
mgp_ptr
Returns the underlying mgp_date pointer.
pub fn mgp_ptr(&self) -> *mut mgp_date- Returns: A pointer to
mgp_date.
set_mgp_ptr
Sets a new mgp_date pointer.
pub fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_date)- Parameters:
new_ptr: A new pointer tomgp_date.
year
Returns the year of the Date.
pub fn year(&self) -> i32- Returns: The year of the
Date.
month
Returns the month of the Date.
pub fn month(&self) -> u32- Returns: The month of the
Date.
day
Returns the day of the Date.
pub fn day(&self) -> u32- Returns: The day of the
Date.
Drop
Drops the Date and releases the associated resources.
fn drop(&mut self)LocalTime
new
Creates a new LocalTime.
pub(crate) fn new(ptr: *mut mgp_local_time) -> LocalTime- Parameters:
ptr: A pointer tomgp_local_time.
- Returns: A new instance of
LocalTime.
from_naive_time
Creates a LocalTime from a NaiveTime.
pub fn from_naive_time(from: &NaiveTime, memgraph: &Memgraph) -> Result<LocalTime>- Parameters:
from: A reference to aNaiveTime.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newLocalTimeif successful.
to_naive_time
Converts the LocalTime to a NaiveTime.
pub fn to_naive_time(&self) -> NaiveTime- Returns: A
NaiveTimerepresenting theLocalTime.
mgp_ptr
Returns the underlying mgp_local_time pointer.
pub fn mgp_ptr(&self) -> *mut mgp_local_time- Returns: A pointer to
mgp_local_time.
set_mgp_ptr
Sets a new mgp_local_time pointer.
pub fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_local_time)- Parameters:
new_ptr: A new pointer tomgp_local_time.
hour
Returns the hour of the LocalTime.
pub fn hour(&self) -> u32- Returns: The hour of the
LocalTime.
minute
Returns the minute of the LocalTime.
pub fn minute(&self) -> u32- Returns: The minute of the
LocalTime.
second
Returns the second of the LocalTime.
pub fn second(&self) -> u32- Returns: The second of the
LocalTime.
millisecond
Returns the millisecond of the LocalTime.
pub fn millisecond(&self) -> u32- Returns: The millisecond of the
LocalTime.
microsecond
Returns the microsecond of the LocalTime.
pub fn microsecond(&self) -> u32- Returns: The microsecond of the
LocalTime.
timestamp
Returns the timestamp of the LocalTime.
pub fn timestamp(&self) -> i64- Returns: The timestamp of the
LocalTime.
Drop
Drops the LocalTime and releases the associated resources.
fn drop(&mut self)LocalDateTime
new
Creates a new LocalDateTime.
pub(crate) fn new(ptr: *mut mgp_local_date_time) -> LocalDateTime- Parameters:
ptr: A pointer tomgp_local_date_time.
- Returns: A new instance of
LocalDateTime.
from_naive_date_time
Creates a LocalDateTime from a NaiveDateTime.
pub fn from_naive_date_time(from: &NaiveDateTime, memgraph: &Memgraph) -> Result<LocalDateTime>- Parameters:
from: A reference to aNaiveDateTime.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newLocalDateTimeif successful.
to_naive_date_time
Converts the LocalDateTime to a NaiveDateTime.
pub fn to_naive_date_time(&self) -> NaiveDateTime- Returns: A
NaiveDateTimerepresenting theLocalDateTime.
mgp_ptr
Returns the underlying mgp_local_date_time pointer.
pub fn mgp_ptr(&self) -> *mut mgp_local_date_time- Returns: A pointer to
mgp_local_date_time.
set_mgp_ptr
Sets a new mgp_local_date_time pointer.
pub fn set_mgp_ptr(&mut self, new_ptr: *mut mgp_local_date_time)- Parameters:
new_ptr: A new pointer tomgp_local_date_time.
year
Returns the year of the LocalDateTime.
pub fn year(&self) -> i32- Returns: The year of the
LocalDateTime.
month
Returns the month of the LocalDateTime.
pub fn month(&self) -> u32- Returns: The month of the
LocalDateTime.
day
Returns the day of the LocalDateTime.
pub fn day(&self) -> u32- Returns: The day of the
LocalDateTime.
hour
Returns the hour of the LocalDateTime.
pub fn hour(&self) -> u32- Returns: The hour of the
LocalDateTime.
minute
Returns the minute of the LocalDateTime.
pub fn minute(&self) -> u32- Returns: The minute of the
LocalDateTime.
second
Returns the second of the LocalDateTime.
pub fn second(&self) -> u32- Returns: The second of the
LocalDateTime.
millisecond
Returns the millisecond of the LocalDateTime.
pub fn millisecond(&self) -> u32- Returns: The millisecond of the
LocalDateTime.
microsecond
Returns the microsecond of the LocalDateTime.
pub fn microsecond(&self) -> u32- Returns: The microsecond of the
LocalDateTime.
Drop
Drops the LocalDateTime and releases the associated resources.
fn drop(&mut self)Duration
new
Creates a new Duration.
pub(crate) fn new(ptr: *mut mgp_duration) -> Duration- Parameters:
ptr: A pointer tomgp_duration.
- Returns: A new instance of
Duration.
from_chrono_duration
Creates a Duration from a chrono::Duration.
pub fn from_chrono_duration(from: &chrono::Duration, memgraph: &Memgraph) -> Result<Duration>- Parameters:
from: A reference to achrono::Duration.memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining a newDurationif successful.
to_chrono_duration
Converts the Duration to a chrono::Duration.
pub fn to_chrono_duration(&self) -> chrono::DurationValue
to_mgp_value
Converts a Value to a MgpValue.
pub fn to_mgp_value(&self, memgraph: &Memgraph) -> Result<MgpValue>- Parameters:
memgraph: A reference to aMemgraphinstance.
- Returns: A
Resultcontaining theMgpValueif successful.
create_cstring
Creates a copy of the provided string.
pub(crate) unsafe fn create_cstring(c_char_ptr: *const c_char) -> Result<CString>- Parameters:
c_char_ptr: A pointer to a C string.
- Returns: A
Resultcontaining aCStringif successful.
mgp_raw_value_to_value
Creates a Value object from a mgp_value object.
pub(crate) unsafe fn mgp_raw_value_to_value(value: *mut mgp_value, memgraph: &Memgraph) -> Result<Value>-
Parameters:
value: A pointer tomgp_value.memgraph: A reference to aMemgraphinstance.
-
Returns: A
Resultcontaining theValueif successful. -
Safety: Calls C API unsafe functions. The provided
mgp_valueobject has to be a valid non-null pointer.
Enums
Value
Represents different types of values.
pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(CString),
Vertex(Vertex),
Edge(Edge),
Path(Path),
List(List),
Map(Map),
Date(NaiveDate),
LocalTime(NaiveTime),
LocalDateTime(NaiveDateTime),
Duration(chrono::Duration),
}- Variants:
Null: Represents a null value.Bool(bool): Represents a boolean value.Int(i64): Represents an integer value.Float(f64): Represents a floating-point value.String(CString): Represents a string value.Vertex(Vertex): Represents a vertex value.Edge(Edge): Represents an edge value.Path(Path): Represents a path value.List(List): Represents a list value.Map(Map): Represents a map value.Date(NaiveDate): Represents a date value.LocalTime(NaiveTime): Represents a local time value.LocalDateTime(NaiveDateTime): Represents a local date-time value.Duration(chrono::Duration): Represents a duration value.