Skip to content

Broaden FitnessObserver blanket impl to accept FnMut closures#150

Merged
HyperCodec merged 2 commits intodevfrom
copilot/sub-pr-148-again
Mar 10, 2026
Merged

Broaden FitnessObserver blanket impl to accept FnMut closures#150
HyperCodec merged 2 commits intodevfrom
copilot/sub-pr-148-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

The blanket FitnessObserver impl was bounded on Fn, which excluded FnMut closures — a common pattern for observers that accumulate state (counters, logs, running stats, etc.), forcing unnecessary use of RefCell or similar wrappers.

Change

  • Relaxed the bound in the blanket FitnessObserver<G> impl from Fn(&[(G, f32)]) to FnMut(&[(G, f32)])

This is a safe widening: every Fn is also FnMut, so no existing code breaks. The observe method already takes &mut self, making FnMut the natural bound.

// Now works without RefCell:
let mut count = 0usize;
let observer = |fitnesses: &[(MyGenome, f32)]| {
    count += 1;
    println!("Generation {count}: {} survivors", fitnesses.len());
};
simulator.run_with_observer(observer);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback from PR #148 for update 1.4.0 Broaden FitnessObserver blanket impl to accept FnMut closures Mar 10, 2026
@HyperCodec HyperCodec marked this pull request as ready for review March 10, 2026 13:06
@HyperCodec HyperCodec merged commit 5ffff28 into dev Mar 10, 2026
4 checks passed
@HyperCodec HyperCodec deleted the copilot/sub-pr-148-again branch March 10, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants