surrealcs 0.4.4

The SurrealCS client code for SurrealDB
Documentation
//! Defines the interface for handling transactions. The user making a call to the server will use one of the interfaces
//! in this module to construct two transaction actors. One transaction actor in the client and one transaction actor in
//! the server. The interfaces in this module can then be used to send key value operations to the server and recieve
//! responses from the server.
pub mod any;
pub mod bridge;
pub mod in_progress;
pub mod interface;
pub mod not_started;
pub mod utils;

// Below is utils that can be used for testing the transaction interfaces. Feel free to break this out into it's own
// testing utils package if there is a need later on.
#[cfg(test)]
mod test_utils {

	/// Generates a mock handle and implements the `SendToTransactionClientActor` trait for the handle so we can pass
	/// this to the transaction handle for testing. For reference on how this is used, please visit one of the
	/// interfaces in this module and see how this is implemented when creating a handle for testing that interface.
	///
	/// # Arguments
	/// * `struct_name`: the name of the struct that is going to be generated with the `SendToTransactionClientActor` implementation
	/// * `match_pattern`: the pattern to match on the message that is passed to the `send_to_transaction_client_actor` function.
	///                    This is used to perform a range of assertions to the message passed to the transaction client actor.
	/// * `return_expr`: the message that is going to be returned from the transaction actor
	#[macro_export]
	macro_rules! generate_mock_handle {
        (
            struct $struct_name:ident;
            match $match_pattern:pat => {
                $($assertion:stmt);* $(;)?
            }
            return $return_expr:expr;
        ) => {
            struct $struct_name;

            async fn return_statement(message: ServerMessage) -> Result<ServerTransactionMessage, NanoServiceError> {
                match message {
                    $match_pattern => {
                        $($assertion)*
                    },
                    _ => {
                        panic!("message not as expected: {:?}", message);
                    }
                }
                $return_expr
            }

            impl SendToTransactionClientActor for $struct_name {
                fn send_to_transaction_client_actor<T: Send>(_self_ref: &mut Transaction<T>, message: ServerMessage) ->
                impl Future<Output = Result<ServerTransactionMessage, NanoServiceError>> + Send {
                    return_statement(message)
                }
            }
        };
    }
}