Struct DataHub

Source
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

Source

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.

Source

pub fn uses<S, C>(&mut self, name: &str, ds: S)
where S: DataSrc<C>, C: DataConn + 'static,

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: The DataSrc instance to register.
Source

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.
Source

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 of DataConn expected.
§Parameters
  • name: The name of the data source/connection to retrieve.
§Returns
  • Result<&mut C, Err>: A mutable reference to the DataConn instance if successful, or an Err if the data source is not found, or if the retrieved/created DataConn cannot be cast to the specified type C.

Trait Implementations§

Source§

impl DataAcc for DataHub

Source§

fn get_data_conn<C: DataConn + 'static>( &mut self, name: &str, ) -> Result<&mut C, Err>

Retrieves a mutable reference to a DataConn object associated with the given name. Read more
Source§

impl Drop for DataHub

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.