Mercerenies / fifi-calculator

1 stars 0 forks source link

Consolidate contexts #90

Open Mercerenies opened 4 months ago

Mercerenies commented 4 months ago

We have too many "context" classes.

Consolidate and clarify what each one means.

Mercerenies commented 4 months ago

Current shapes (as of 9de2c93) of the relevant structs:

pub struct CommandContext<'a, 'b> {
  pub opts: CommandOptions,
  pub simplifier: Box<dyn Simplifier + 'a>,
  pub units_parser: &'b dyn UnitParser<Number>,
}

pub struct FunctionContext<'a, 'b, 'c> {
  pub errors: &'a mut ErrorList<SimplifierError>,
  pub simplifier: &'b dyn Simplifier,
  pub function_table: &'c FunctionTable,
  _private: (),
}

pub struct ValidationContext<'a, 'b> {
  pub units_parser: &'a dyn UnitParser<Number>,
  pub language_mode: &'b dyn LanguageMode,
}

pub struct QueryContext<'a> {
  pub units_parser: &'a dyn UnitParser<Number>,
}

pub struct SimplifierContext<'a, 'b> {
  pub base_simplifier: &'a dyn Simplifier,
  pub errors: &'b mut ErrorList<SimplifierError>,
}
Mercerenies commented 4 months ago

And here's where we construct each of them:

CommandContext:

FunctionContext:

ValidationContext:

QueryContext:

SimplifierContext: