pub struct DataHub { /* private fields */ }Expand description
The struct that acts as a central hub for data input/output operations, integrating
multiple Data traits (which are passed to business logic functions as their arguments) with
DataAcc traits (which implement default data I/O methods for external services).
It facilitates data access by providing DataConn objects, created from
both global data sources (registered via the global uses function) and
session-local data sources (registered via DataHub::uses method).
The DataHub is capable of performing aggregated transactional operations
on all DataConn objects created from its registered DataSrc instances.
Implementations§
Source§impl DataHub
impl DataHub
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new DataHub instance.
Upon creation, it attempts to “fix” the global data sources (making them immutable for further registration) and copies references to already set-up global data sources into its internal map for quick access.
Sourcepub fn uses<S, C>(&mut self, name: &str, ds: S)
pub fn uses<S, C>(&mut self, name: &str, ds: S)
Registers a session-local data source with this DataHub instance.
This method is similar to the global uses function but registers a data source
that is local to this specific DataHub session. Once the DataHub’s state is
“fixed” (while run! or txn! macro is executing), further calls
to uses are ignored. However, after run! or txn! completes, the DataHub’s
“fixed” state is reset, allowing for new data sources to be registered or removed
via disuses method in subsequent operations.
§Parameters
name: The unique name for the local data source.ds: TheDataSrcinstance to register.
Sourcepub fn disuses(&mut self, name: &str)
pub fn disuses(&mut self, name: &str)
Unregisters and drops a session-local data source by its name.
This method removes a data source that was previously registered via DataHub::uses.
This operation is ignored if the DataHub’s state is already “fixed”.
§Parameters
name: The name of the local data source to unregister.
Sourcepub fn get_data_conn<C>(&mut self, name: &str) -> Result<&mut C, Err>where
C: DataConn + 'static,
pub fn get_data_conn<C>(&mut self, name: &str) -> Result<&mut C, Err>where
C: DataConn + 'static,
Retrieves a mutable reference to a DataConn object by name, creating it if necessary.
This is the core method used by DataAcc implementations to obtain connections
to external data services. It first checks if a DataConn with the given name
already exists in the DataHub’s session. If not, it attempts to find a
corresponding DataSrc and create a new DataConn from it.
§Type Parameters
C: The concrete type ofDataConnexpected.
§Parameters
name: The name of the data source/connection to retrieve.
§Returns
Result<&mut C, Err>: A mutable reference to theDataConninstance if successful, or anErrif the data source is not found, or if the retrieved/createdDataConncannot be cast to the specified typeC.