ultima-ib / ultima

The Ultimate BI tool
https://ultimabi.uk/
Other
7 stars 0 forks source link

DataSource as a Trait #167

Open AnatolyBuga opened 1 year ago

AnatolyBuga commented 1 year ago

It would be better if DataSource was a Trait.

//TODO - consider this:
/// Trait which defines the behavior of a a Source of Data
/// examples:
pub trait DataSource: Send + Sync {
    fn get_lazyframe(&self, filters: &AndOrFltrChain) -> UltiResult<LazyFrame>;
    fn get_column(&self, col_name: &str) -> UltiResult<Series> ;
    fn get_schema(&self) -> UltiResult<Arc<Schema>>;

    /// InMemory -> false
    /// Scan -> true
    /// Db -> true
    fn prepare_on_each_request(&self) -> bool;
}

// As per example:
use std::sync::Arc;

struct Empty;
struct Null;

trait P {
    fn u(&self) -> u8
    where Self: Sized {1}
}

impl P for Empty{}

trait GeeksforGeeks{
    type X;
    fn gfg_func(&self) -> Self::X;
}

impl <U> GeeksforGeeks for U {
    type X = Arc<dyn P>;
    fn gfg_func(&self) -> Self::X {
        Arc::new(Empty{})
    }
}

fn main() {
    let variable_one = Empty;
    let variable_two  = Null;

    let obj: Box<dyn GeeksforGeeks<X=Arc<dyn P>>> = Box::new(variable_two);

    obj.gfg_func();

}