Trait DataSrc

Source
pub trait DataSrc<C>
where C: DataConn + 'static,
{ // Required methods fn setup(&mut self, ag: &mut AsyncGroup<'_>) -> Result<(), Err>; fn close(&mut self); fn create_data_conn(&mut self) -> Result<Box<C>, Err>; }
Expand description

The trait that abstracts a data source responsible for managing connections to external data services, such as databases, file systems, or messaging services.

It receives configuration for connecting to an external data service and then creates and supplies DataConn instance, representing a single session connection.

Required Methods§

Source

fn setup(&mut self, ag: &mut AsyncGroup<'_>) -> Result<(), Err>

Performs the setup process for the data source.

This method is responsible for establishing global connections, configuring connection pools, or performing any necessary initializations required before DataConn instances can be created.

§Parameters
  • ag: A mutable reference to an AsyncGroup. This is used if the setup process is potentially time-consuming and can benefit from asynchronous execution.
§Returns
  • Result<(), Err>: Ok(()) if the setup is successful, or an Err if any part of the setup fails.
Source

fn close(&mut self)

Closes the data source and releases any globally held resources.

This method should perform cleanup operations, such as closing global connections or shutting down connection pools, that were established during the setup phase.

Source

fn create_data_conn(&mut self) -> Result<Box<C>, Err>

Creates a new DataConn instance which is a connection per session.

Each call to this method should yield a distinct DataConn object tailored for a single session’s operations.

§Returns
  • Result<Box<C>, Err>: Ok(Box<C>) containing the newly created DataConn if successful, or an Err if the connection could not be created.

Implementors§