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 (opens in a new tab).
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
Memgraph
with default values.
args
Returns the arguments passed to the procedure call.
pub fn args(&self) -> Result<List>
- Returns: A
Result
containing theList
of 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
Result
containing aVerticesIterator
if 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
Result
containing theVertex
if successful.
result_record
Creates a new result record.
pub fn result_record(&self) -> Result<ResultRecord>
- Returns: A
Result
containing a newResultRecord
if 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 allNamedType
s, each one defined by name and an array ofType
s.optional_arg_types
: An array of allOptionalNamedType
s, each one defined by name, an array ofType
s, and default value.result_field_types
: An array of allNamedType
s, each one defined by name and an array ofType
s.
- Returns: A
Result
indicating 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:
true
if the procedure should abort,false
otherwise.
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
Option
containing anMgpError
if 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 ofType
s.
- 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 aMemgraph
instance.
- Returns: A new instance of
VerticesIterator
.
next
Returns the next vertex in the iteration.
fn next(&mut self) -> Option<Vertex>
- Returns: An
Option
containing the nextVertex
if 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 aMemgraph
instance.
- 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 aMemgraph
instance.
- Returns: A
Result
containing a newVertex
instance 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
Result
containing the number of labels asu64
if 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
Result
containing the label as aCString
if 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
Result
containingtrue
if theVertex
has 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
Result
containing theProperty
if successful.
properties
Returns an iterator over the properties of the Vertex
.
pub fn properties(&self) -> Result<PropertiesIterator>
- Returns: A
Result
containing aPropertiesIterator
if successful.
in_edges
Returns an iterator over the incoming edges of the Vertex
.
pub fn in_edges(&self) -> Result<EdgesIterator>
- Returns: A
Result
containing anEdgesIterator
if successful.
out_edges
Returns an iterator over the outgoing edges of the Vertex
.
pub fn out_edges(&self) -> Result<EdgesIterator>
- Returns: A
Result
containing anEdgesIterator
if 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 aMemgraph
instance.
- Returns: A new instance of
EdgesIterator
.
next
Returns the next edge in the iteration.
fn next(&mut self) -> Option<Edge>
- Returns: An
Option
containing the nextEdge
if 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 aMemgraph
instance.
- 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 aMemgraph
instance.
- Returns: A
Result
containing a newEdge
instance 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
Result
containing the copiedEdge
if 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
Result
containing the type of theEdge
as aCString
if successful.
from_vertex
Returns the vertex from which the Edge
originates.
pub fn from_vertex(&self) -> Result<Vertex>
- Returns: A
Result
containing the originatingVertex
if successful.
to_vertex
Returns the vertex to which the Edge
points.
pub fn to_vertex(&self) -> Result<Vertex>
- Returns: A
Result
containing the destinationVertex
if 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
Result
containing theProperty
if successful.
properties
Returns an iterator over the properties of the Edge
.
pub fn properties(&self) -> Result<PropertiesIterator>
- Returns: A
Result
containing aPropertiesIterator
if 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 aMemgraph
instance.
- 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 aMemgraph
instance.
- Returns: A
Result
containing a newList
if 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 aMemgraph
instance.
- Returns: A
Result
containing a copiedList
if successful.
copy
Creates a copy of the current List
.
pub fn copy(&self) -> Result<List>
- Returns: A
Result
containing the copiedList
if 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
: TheValue
to append.
- Returns: A
Result
indicating 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
: TheValue
to append.
- Returns: A
Result
indicating 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
Result
containing theValue
if successful.
iter
Returns an iterator over the List
.
pub fn iter(&self) -> Result<ListIterator>
- Returns: A
Result
containing aListIterator
if 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
Option
containing the nextValue
if 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 aMemgraph
instance.
- 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 aMemgraph
instance.
- Returns: A
Result
containing a copiedMap
if successful.
make_empty
Creates an empty Map
.
pub fn make_empty(memgraph: &Memgraph) -> Result<Map>
- Parameters:
memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a new emptyMap
if 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
Result
indicating 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
Result
containing theValue
if successful.
iter
Returns an iterator over the Map
.
pub fn iter(&self) -> Result<MapIterator>
- Returns: A
Result
containing aMapIterator
if 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 aMemgraph
instance.
- Returns: A new instance of
MapIterator
.
next
Returns the next item in the iteration.
fn next(&mut self) -> Option<MapItem>
- Returns: An
Option
containing the nextMapItem
if 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 aMemgraph
instance.
- 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
Result
containing theValue
if successful.
make_null
Creates a MgpValue
representing a null value.
pub fn make_null(memgraph: &Memgraph) -> Result<MgpValue>
- Parameters:
memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_null
Checks if the MgpValue
is null.
pub fn is_null(&self) -> bool
- Returns:
true
if theMgpValue
is 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 aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_bool
Checks if the MgpValue
is a boolean.
pub fn is_bool(&self) -> bool
- Returns:
true
if theMgpValue
is 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 aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_int
Checks if the MgpValue
is an integer.
pub fn is_int(&self) -> bool
- Returns:
true
if theMgpValue
is 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 aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_double
Checks if the MgpValue
is a double.
pub fn is_double(&self) -> bool
- Returns:
true
if theMgpValue
is 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 aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_string
Checks if the MgpValue
is a string.
pub fn is_string(&self) -> bool
- Returns:
true
if theMgpValue
is a string, otherwisefalse
.
make_list
Creates a MgpValue
representing a list value.
pub fn make_list(list: &List, memgraph: &Memgraph) -> Result<MgpValue>
- Parameters:
list
: TheList
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_list
Checks if the MgpValue
is a list.
pub fn is_list(&self) -> bool
- Returns:
true
if theMgpValue
is a list, otherwisefalse
.
make_map
Creates a MgpValue
representing a map value.
pub fn make_map(map: &Map, memgraph: &Memgraph) -> Result<MgpValue>
- Parameters:
map
: TheMap
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_map
Checks if the MgpValue
is a map.
pub fn is_map(&self) -> bool
- Returns:
true
if theMgpValue
is a map, otherwisefalse
.
make_vertex
Creates a MgpValue
representing a vertex value.
pub fn make_vertex(vertex: &Vertex, memgraph: &Memgraph) -> Result<MgpValue>
- Parameters:
vertex
: TheVertex
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_vertex
Checks if the MgpValue
is a vertex.
pub fn is_vertex(&self) -> bool
- Returns:
true
if theMgpValue
is a vertex, otherwisefalse
.
make_edge
Creates a MgpValue
representing an edge value.
pub fn make_edge(edge: &Edge, memgraph: &Memgraph) -> Result<MgpValue>
- Parameters:
edge
: TheEdge
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_edge
Checks if the MgpValue
is an edge.
pub fn is_edge(&self) -> bool
- Returns:
true
if theMgpValue
is an edge, otherwisefalse
.
make_path
Creates a MgpValue
representing a path value.
pub fn make_path(path: &Path, memgraph: &Memgraph) -> Result<MgpValue>
- Parameters:
path
: ThePath
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_path
Checks if the MgpValue
is a path.
pub fn is_path(&self) -> bool
- Returns:
true
if theMgpValue
is a path, otherwisefalse
.
make_date
Creates a MgpValue
representing a date value.
pub fn make_date(date: &NaiveDate, memgraph: &Memgraph) -> Result<MgpValue>
- Parameters:
date
: TheNaiveDate
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_date
Checks if the MgpValue
is a date.
pub fn is_date(&self) -> bool
- Returns:
true
if theMgpValue
is 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
: TheNaiveTime
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_local_time
Checks if the MgpValue
is a local time.
pub fn is_local_time(&self) -> bool
- Returns:
true
if theMgpValue
is 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
: TheNaiveDateTime
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_local_date_time
Checks if the MgpValue
is a local date-time.
pub fn is_local_date_time(&self) -> bool
- Returns:
true
if theMgpValue
is 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
: TheDuration
to be converted.memgraph
: A reference to aMemgraph
instance.
- Returns: A
Result
containing a newMgpValue
if successful.
is_duration
Checks if the MgpValue
is a duration.
pub fn is_duration(&self) -> bool
- Returns:
true
if theMgpValue
is 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 aMemgraph
instance.
- 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 aMemgraph
instance.
- Returns: A
Result
containing a copiedPath
if 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 aMemgraph
instance.
- Returns: A
Result
containing a newPath
if 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
: TheEdge
to add.
- Returns: A
Result
indicating 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 theVertex
to retrieve.
- Returns: A
Result
containing theVertex
if successful.
edge_at
Returns the Edge
at the specified index.
pub fn edge_at(&self, index: u64) -> Result<Edge>
- Parameters:
index
: The index of theEdge
to retrieve.
- Returns: A
Result
containing theEdge
if 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 aMemgraph
instance.
- Returns: A new instance of
PropertiesIterator
.
next
Returns the next property in the iteration.
fn next(&mut self) -> Option<Property>
- Returns: An
Option
containing the nextProperty
if 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 aMemgraph
instance.
- Returns: A
Result
containing a newResultRecord
if 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
: TheMgpValue
to insert.
- Returns: A
Result
indicating 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
Result
indicating 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
Result
indicating 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
Result
indicating 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
Result
indicating 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 aCStr
to insert.
- Returns: A
Result
indicating 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
: TheList
to insert.
- Returns: A
Result
indicating 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
: TheMap
to insert.
- Returns: A
Result
indicating 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
: TheVertex
to insert.
- Returns: A
Result
indicating 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
: TheEdge
to insert.
- Returns: A
Result
indicating 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
: ThePath
to insert.
- Returns: A
Result
indicating 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
: TheNaiveDate
to insert.
- Returns: A
Result
indicating 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
: TheNaiveTime
to insert.
- Returns: A
Result
indicating 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
: TheNaiveDateTime
to insert.
- Returns: A
Result
indicating 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
: TheDuration
to insert.
- Returns: A
Result
indicating 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 aMemgraph
instance.
- Returns: A
Result
containing a newDate
if successful.
to_naive_date
Converts the Date
to a NaiveDate
.
pub fn to_naive_date(&self) -> NaiveDate
- Returns: A
NaiveDate
representing 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 aMemgraph
instance.
- Returns: A
Result
containing a newLocalTime
if successful.
to_naive_time
Converts the LocalTime
to a NaiveTime
.
pub fn to_naive_time(&self) -> NaiveTime
- Returns: A
NaiveTime
representing 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
.