Skip to content

Refactor write_view_segment in MDL writer to reduce parameter count #406

@bpowers

Description

@bpowers

Description

The write_view_segment function in src/simlin-engine/src/mdl/writer.rs takes 8 parameters, which triggers clippy's too_many_arguments lint. The lint is currently suppressed with #[allow(clippy::too_many_arguments)].

Several of the parameters represent shared context that is threaded through the function: valve_uids, elem_positions, name_map, next_connector_uid, etc. These should be grouped into a context struct (e.g., ViewWriteContext) to improve readability and reduce the function signature size.

Why it matters

  • Maintainability: Long parameter lists make it harder to understand what the function needs and easier to mix up arguments at call sites.
  • Clippy compliance: Suppressing lints with #[allow(...)] should be a last resort, not a permanent fixture. Reducing the parameter count removes the need for the suppression.
  • Developer experience: A context struct makes it clearer which pieces of state are related and passed together.

Component(s) affected

  • src/simlin-engine/src/mdl/writer.rs -- the write_view_segment function

Possible approach

Introduce a struct (e.g., ViewWriteContext) that bundles the shared parameters:

  • valve_uids
  • elem_positions
  • name_map
  • next_connector_uid
  • any other context that is passed through multiple writer functions

Then replace the individual parameters with a single &mut ViewWriteContext reference.

Context

Identified during review of PR #397 (mdl-roundtrip-fidelity branch). This is a code quality improvement that does not affect correctness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions