pub struct DataContainer {
pub df: Arc<DataFrame>,
pub df_original: Arc<DataFrame>,
pub extension: Arc<FileExtension>,
pub filter: Arc<DataFilter>,
pub format: Arc<DataFormat>,
pub sort: Vec<SortBy>,
}Expand description
Container for the Polars DataFrame and its associated display and filter state.
§State Management:
- Holds the core data (
df,df_original) and related settings. df: The currently displayed DataFrame, potentially sorted based onself.sort.df_original: The DataFrame state immediately after loading/querying, before UI sorts.filter: Configuration used for loading the data (path, delimiter, SQL query, etc.). Does NOT contain sorting information.format: Configuration for displaying the data (alignment, decimals, etc.).sort:Vec<SortBy>defining the active sort order applied todf. An empty Vec meansdfreflectsdf_original.- All key components are wrapped in
Arcfor efficient cloning and sharing between UI and async tasks. - Updates (load, format, sort) typically create new
DataContainerinstances via async methods.
§Interaction with layout.rs:
PolarsViewAppholds the current state asOption<Arc<DataContainer>>.- UI actions trigger async methods here (
load_data,update_format,apply_sort). - Async methods return
PolarsViewResult<DataContainer>via a channel. layout.rsupdates the app state with the received new container.
Fields§
§df: Arc<DataFrame>The currently displayed Polars DataFrame. May be sorted according to self.sort.
df_original: Arc<DataFrame>A reference to the DataFrame state before any UI-driven sort was applied. Allows resetting the view efficiently.
extension: Arc<FileExtension>Detected file extension of the originally loaded data.
filter: Arc<DataFilter>Filters and loading configurations (path, query, delimiter) that resulted
in the initial df_original. This does NOT store the current sort state.
format: Arc<DataFormat>Applied data formatting settings (decimal places, alignment, column sizing, header style).
sort: Vec<SortBy>The active sort criteria (column name and direction) applied to df.
An empty vector signifies that df should be the same as df_original.
Order in the vector determines sort precedence.
Implementations§
Source§impl DataContainer
impl DataContainer
Sourcepub async fn load_data(
self,
filter: DataFilter,
format: DataFormat,
) -> PolarsViewResult<Self>
pub async fn load_data( self, filter: DataFilter, format: DataFormat, ) -> PolarsViewResult<Self>
Asynchronously loads data or applies transformations based on DataFilter.
Returns a new DataContainer state (taken and returned by value).
This function coordinates the sequence of transformations using the Strategy pattern.
§Flow:
- Get the initial DataFrame value (either by reading file or cloning
df_original) viaprepare_initial_dataframe. This also updatesself.extension,self.df_original, andfilter.schema_without_indexif a file was read. - Build the pipeline vector
transformationsby pushing concrete strategy instances based on flags in thefilter. - Reset
filter.apply_sqlflag if SQL transformation was included in the pipeline. - Execute the pipeline: Iterate through the
transformationsvector, callingapplyon each, chaining the output DataFrame. - Update the final
filter.schemabased on the DataFrame’s state after all transformations. - Update
self.df,self.filter,self.format, and resetself.sortwith the results of this operation. - Return the modified
self.
Sourcepub async fn update_format(self, format: DataFormat) -> PolarsViewResult<Self>
pub async fn update_format(self, format: DataFormat) -> PolarsViewResult<Self>
Asynchronously creates a new DataContainer with updated format settings.
Preserves the existing data (df, df_original) and sort criteria (sort).
Triggered by layout.rs when format UI elements change. This is a very fast operation.
Sourcepub async fn apply_sort(
self,
new_sort_criteria: Vec<SortBy>,
) -> PolarsViewResult<Self>
pub async fn apply_sort( self, new_sort_criteria: Vec<SortBy>, ) -> PolarsViewResult<Self>
Asynchronously creates a new DataContainer with the df sorted according
to the provided new_sort_criteria.
Triggered by layout.rs after a user clicks a sortable header, resulting in new criteria.
Handles multi-column sorting based on the order, direction, and nulls_last settings
in new_sort_criteria.
If new_sort_criteria is empty, it resets the view by setting df to df_original.
§Logic & State Update:
- Check if
new_sort_criteriais empty. - Handle Empty (Reset): If empty, create new container:
df: ClonedArcof the inputdf_original.df_original: ClonedArcof the inputdf_original.sort: The emptynew_sort_criteriavector.- Other fields cloned from input container.
- Handle Non-Empty (Apply Sort): If not empty:
a. Extract column names, descending flags, and nulls_last flags from
new_sort_criteria. b. Configure PolarsSortMultipleOptions. c. Calldata_container.df.sort()using the currently displayed df as input. d. Create new container:df: NewArcwrapping the sorted DataFrame.df_original: ClonedArcof the inputdf_original.sort: Thenew_sort_criteriathat caused this sort.- Other fields cloned from input container.
- Return
Ok(new_container).
Trait Implementations§
Source§impl Clone for DataContainer
impl Clone for DataContainer
Source§fn clone(&self) -> DataContainer
fn clone(&self) -> DataContainer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DataContainer
impl Debug for DataContainer
Auto Trait Implementations§
impl Freeze for DataContainer
impl !RefUnwindSafe for DataContainer
impl Send for DataContainer
impl Sync for DataContainer
impl Unpin for DataContainer
impl !UnwindSafe for DataContainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more