Crate mentat_ffi [−] [src]
This module exposes an Foreign Function Interface (FFI) that allows Mentat to be called from other languages.
Functions that are available to other languages in this module are defined as
extern "C" functions which allow them to be layed out correctly for the
platform's C ABI. They all have a #[no_mangle]
decorator to ensure
Rust's name mangling is turned off, so that it is easier to link to.
Mentat's FFI contains unsafe code. As it is an interface between foreign code and native Rust code, Rust cannot guarantee that the types and data that have been passed to it from another language are present and in the format it is expecting. This interface is designed to ensure that nothing unsafe passes through this module and enters Mentat proper
Structs defined with #[repr(C)]
are guaranteed to have a layout that is compatible
with the platform's representation in C.
This API passes pointers in two ways, depending on the lifetime of the value and what value owns it. Pointers to values that are guaranteed to live beyond the lifetime of the function, are passed over the FFI as a raw pointer.
value as *const Binding
Pointers to values that cannot be guaranteed to live beyond the lifetime of the function
are first Box
ed so that they live on the heap, and the raw pointer passed this way.
Box::into_raw(Box::new(value))
The memory for a value that is moved onto the heap before being passed over the FFI
is no longer managed by Rust, but Rust still owns the value. Therefore the pointer
must be returned to Rust in order to be released. To this effect a number of destructor
functions are provided for each Rust value type that is passed, as is a catch all destructor
to release memory for #[repr(C)]
values.
The destructors reclaim the memory via Box and then drop the reference, causing the
memory to be released.
A macro has been provided to make defining destructors easier.
define_destructor!(query_builder_destroy, QueryBuilder);
Passing a pointer to memory that has already been released will cause Mentat to crash, so callers have to be careful to ensure they manage their pointers properly. Failure to call a destructor for a value on the heap will cause a memory leak.
Generally, the functions exposed in this module have a direct mapping to existing Mentat APIs,
in order to keep application logic to a minumum and provide the greatest flexibility
for callers using the interface. However, in some cases a single convenience function
has been provided in order to make the interface easier to use and reduce the number
of calls that have to be made over the FFI to perform a task. An example of this is
store_register_observer
, which takes a single native callback function that is then
wrapped inside a Rust closure and added to a TxObserver struct. This is then used to
register the observer with the store.
Functions that may fail take an out parameter of type *mut ExternError
. In the event the
function fails, information about the error that occured will be stored inside it (and,
typically, a null pointer will be returned). Convenience functions for unpacking a
Result<T, E>
as a *mut T
while writing any error to the ExternError
are provided as
translate_result
, translate_opt_result
(for Result<Option<T>>
) and translate_void_result
(for Result<(), T>
). Callers are responsible for freeing the message
field of ExternError
.
Re-exports
pub use utils::strings::c_char_to_string; |
pub use utils::strings::kw_from_string; |
pub use utils::strings::string_to_c_char; |
pub use utils::log; |
Modules
android | |
utils |
Macros
assert_not_null |
Helper macro for asserting one or more pointers are not null at the same time. |
Structs
EntityBuilder | |
InProgress |
Represents an in-progress, not yet committed, set of changes to the store.
Call |
InProgressBuilder | |
InProgressTransactResult | |
KnownEntid |
An entid that's either already in the store, or newly allocated to a tempid. TODO: we'd like to link this in some way to the lifetime of a particular PartitionMap. |
QueryBuilder | |
QueryInputs |
Define the inputs to a query. This is in two parts: a set of values known now, and a set of
types known now.
The separate map of types is to allow queries to be algebrized without full knowledge of
the bindings that will be used at execution time.
When built correctly, |
QueryOutput | |
RelResult |
The result you get from a 'rel' query, like: |
Store |
A convenience wrapper around a single SQLite connection and a Conn. This is suitable for applications that don't require complex connection management. |
TransactionChange |
A C representation of the change provided by the transaction observers from a single transact. Holds a transaction identifier, the changes as a set of affected attributes and the length of the list of changes. |
TxChangeList |
A C representation of the list of changes provided by the transaction observers. Provides the list of changes as the length of the list. |
TxObserver | |
TxReport |
A transaction report summarizes an applied transaction. |
Uuid |
A Universally Unique Identifier (UUID). |
Variable |
Enums
Binding |
The values bound in a query specification can be: |
CacheDirection | |
FindSpec |
A definition of the first part of a find query: the
|
QueryResults | |
TypedValue |
Represents a value that can be stored in a Mentat store. |
ValueType |
The attribute of each Mentat assertion has a :db/valueType constraining the value to a particular set. Mentat recognizes the following :db/valueType values. |
Traits
BuildTerms | |
HasSchema | |
IntoThing | |
Queryable | |
Syncable |
Functions
changelist_entry_at⚠ |
Returns the value at the provided |
destroy⚠ | |
entity_builder_add_boolean⚠ |
Uses |
entity_builder_add_double⚠ |
Uses |
entity_builder_add_keyword⚠ |
Uses |
entity_builder_add_long⚠ |
Uses |
entity_builder_add_ref⚠ |
Uses |
entity_builder_add_string⚠ |
Uses |
entity_builder_add_timestamp⚠ |
Uses |
entity_builder_add_uuid⚠ |
Uses |
entity_builder_commit⚠ |
Transacts and commits all the assertions and retractions that have been performed using this builder. |
entity_builder_destroy⚠ | |
entity_builder_retract_boolean⚠ |
Uses |
entity_builder_retract_double⚠ |
Uses |
entity_builder_retract_keyword⚠ |
Uses |
entity_builder_retract_long⚠ |
Uses |
entity_builder_retract_ref⚠ |
Uses |
entity_builder_retract_string⚠ |
Uses |
entity_builder_retract_timestamp⚠ |
Uses |
entity_builder_retract_uuid⚠ |
Uses |
entity_builder_transact⚠ |
Transacts all the assertions and retractions that have been performed using this builder. |
in_progress_builder⚠ |
Creates a builder using the in progress transaction to allow for programmatic assertion of values. |
in_progress_builder_add_boolean⚠ |
Uses |
in_progress_builder_add_double⚠ |
Uses |
in_progress_builder_add_keyword⚠ |
Uses |
in_progress_builder_add_long⚠ |
Uses |
in_progress_builder_add_ref⚠ |
Uses |
in_progress_builder_add_string⚠ |
Uses |
in_progress_builder_add_timestamp⚠ |
Uses |
in_progress_builder_add_uuid⚠ |
Uses |
in_progress_builder_commit⚠ |
Transacts and commits all the assertions and retractions that have been performed using this builder. |
in_progress_builder_destroy⚠ | |
in_progress_builder_retract_boolean⚠ |
Uses |
in_progress_builder_retract_double⚠ |
Uses |
in_progress_builder_retract_keyword⚠ |
Uses |
in_progress_builder_retract_long⚠ |
Uses |
in_progress_builder_retract_ref⚠ |
Uses |
in_progress_builder_retract_string⚠ |
Uses |
in_progress_builder_retract_timestamp⚠ |
Uses |
in_progress_builder_retract_uuid⚠ |
Uses |
in_progress_builder_transact⚠ |
Transacts all the assertions and retractions that have been performed using this builder. |
in_progress_commit⚠ |
Commit all the transacts that have been performed using this in progress transaction. |
in_progress_destroy⚠ | |
in_progress_entity_builder_from_entid⚠ |
Creates a builder for an entity with |
in_progress_entity_builder_from_temp_id⚠ |
Creates a builder for an entity with |
in_progress_rollback⚠ |
Rolls back all the transacts that have been performed using this in progress transaction. |
in_progress_transact⚠ |
Perform a single transact operation using the current in progress transaction. Takes edn as a string to transact. |
query_builder_bind_boolean⚠ |
Binds a TypedValue::Boolean to a Variable with the given name. |
query_builder_bind_double⚠ |
Binds a TypedValue::Double to a Variable with the given name. |
query_builder_bind_kw⚠ |
Binds a TypedValue::Ref to a Variable with the given name. Takes a keyword as a c string in the format
|
query_builder_bind_long⚠ |
Binds a TypedValue::Long to a Variable with the given name. |
query_builder_bind_ref⚠ |
Binds a TypedValue::Ref to a Variable with the given name. |
query_builder_bind_ref_kw⚠ |
Binds a TypedValue::Ref to a Variable with the given name. Takes a keyword as a c string in the format
|
query_builder_bind_string⚠ |
Binds a TypedValue::String to a Variable with the given name. |
query_builder_bind_timestamp⚠ |
Binds a TypedValue::Instant to a Variable with the given name. Takes a timestamp in microseconds. |
query_builder_bind_uuid⚠ |
Binds a TypedValue::Uuid to a Variable with the given name.
Takes a |
query_builder_destroy⚠ | |
query_builder_execute⚠ |
Executes a query and returns the results as a Rel. |
query_builder_execute_coll⚠ |
Executes a query and returns the results as a Coll. |
query_builder_execute_scalar⚠ |
Executes a query and returns the results as a Scalar. |
query_builder_execute_tuple⚠ |
Executes a query and returns the results as a Tuple. |
row_at_index⚠ |
Returns the value at the provided |
rust_c_string_destroy⚠ | |
store_begin_transaction⚠ |
Starts a new transaction to allow multiple transacts to be performed together. This is more efficient than performing a large set of individual commits. |
store_cache_attribute_bi_directional⚠ |
Adds an attribute to the cache.
|
store_cache_attribute_forward⚠ |
Adds an attribute to the cache.
|
store_cache_attribute_reverse⚠ |
Adds an attribute to the cache.
|
store_destroy⚠ | |
store_entid_for_attribute⚠ |
Returns the Entid associated with the |
store_entity_builder_from_entid⚠ |
Starts a new transaction and creates a builder for an entity with |
store_entity_builder_from_temp_id⚠ |
Starts a new transaction and creates a builder for an entity with |
store_in_progress_builder⚠ |
Starts a new transaction and creates a builder using the transaction to allow for programmatic assertion of values. |
store_open |
A store cannot be opened twice to the same location.
Once created, the reference to the store is held by the caller and not Rust,
therefore the caller is responsible for calling |
store_query⚠ |
Creates a QueryBuilder from the given store to execute the provided query. |
store_register_observer⚠ |
Registers a TxObserver with the |
store_transact⚠ |
Performs a single transaction against the store. |
store_unregister_observer⚠ |
Unregisters a TxObserver with the |
store_value_for_attribute⚠ |
Returns a pointer to the the Binding associated with the |
tx_change_list_entry_at⚠ |
Returns the value at the provided |
tx_report_destroy⚠ | |
tx_report_entity_for_temp_id⚠ |
Fetches the Entid assigned to the |
tx_report_get_entid⚠ |
Fetches the |
tx_report_get_tx_instant⚠ |
Fetches the |
typed_value_destroy⚠ | |
typed_value_into_boolean⚠ |
Consumes a Binding and returns the value as a boolean represented as an |
typed_value_into_double⚠ |
Consumes a Binding and returns the value as a |
typed_value_into_entid⚠ | |
typed_value_into_kw⚠ |
Consumes a Binding and returns the value as an keyword C |
typed_value_into_long⚠ |
Consumes a Binding and returns the value as a C |
typed_value_into_string⚠ |
Consumes a Binding and returns the value as a C |
typed_value_into_timestamp⚠ |
Consumes a Binding and returns the value as a microsecond timestamp. |
typed_value_into_uuid⚠ |
Consumes a Binding and returns the value as a UUID byte slice of length 16. |
typed_value_list_destroy⚠ | |
typed_value_list_into_iter⚠ |
Consumes the |
typed_value_list_iter_destroy⚠ | |
typed_value_list_iter_next⚠ |
Returns the next value in the |
typed_value_result_set_destroy⚠ | |
typed_value_result_set_into_iter⚠ |
Consumes the |
typed_value_result_set_iter_destroy⚠ | |
typed_value_result_set_iter_next⚠ |
Returns the next value in the |
typed_value_value_type⚠ | |
uuid_destroy⚠ | |
value_at_index⚠ |
Returns the value at the provided |
value_at_index_into_boolean⚠ |
Returns the value of the Binding at |
value_at_index_into_double⚠ |
Returns the value of the Binding at |
value_at_index_into_entid⚠ | |
value_at_index_into_kw⚠ |
Returns the value of the Binding at |
value_at_index_into_long⚠ |
Returns the value of the Binding at |
value_at_index_into_string⚠ |
Returns the value of the Binding at |
value_at_index_into_timestamp⚠ |
Returns the value of the Binding at |
value_at_index_into_uuid⚠ |
Returns the value of the Binding at |
Type Definitions
BindingIterator | |
BindingListIterator | |
Entid |
Represents one entid in the entid space. |