Skip to content

fix(closure-types): correct checkout_cart trait from FnOnce to Fn#184

Open
juliusjulyp wants to merge 1 commit into
rustfinity:mainfrom
juliusjulyp:fix/typed-closures-checkout-cart-trait
Open

fix(closure-types): correct checkout_cart trait from FnOnce to Fn#184
juliusjulyp wants to merge 1 commit into
rustfinity:mainfrom
juliusjulyp:fix/typed-closures-checkout-cart-trait

Conversation

@juliusjulyp

Copy link
Copy Markdown

What

Corrects the closure trait label for checkout_cart in the closure-types
challenge from FnOnce to Fn.

Why

checkout_cart captures nothing from the environment. The String it
operates on is passed as a parameter, not captured. A closure only becomes
FnOnce when it moves captured environment state out on the first call.
This is not happening here — the closure can be called multiple times with
different String arguments, which is the definition of Fn.

Changes

  • description.md — corrected trait label from FnOnce to Fn
  • src/lib.rs — corrected return type annotation from FnOnce to Fn
  • tests/tests.rs — removed test enforcing wrong FnOnce behavior,
    added test_checkout_cart_multiple_calls confirming correct Fn semantics

checkout_cart captures nothing from the environment. The String it
operates on is passed as a parameter, not captured. A closure only
becomes FnOnce when it moves captured environment state out on the
first call. Since the closure has no internal state to deplete,
it correctly implements Fn and can be called multiple times.

- Updated description.md to label checkout_cart as Fn
- Updated return type annotation in lib.rs from FnOnce to Fn
- Removed test_fn_once_should_work_once which enforced incorrect behavior
- Added test_checkout_cart_multiple_calls to verify Fn semantics
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 56ea9e6a-4b80-41d0-a79a-b20b01976573

📥 Commits

Reviewing files that changed from the base of the PR and between a2179b0 and 913ea7f.

📒 Files selected for processing (3)
  • challenges/closure-types/description.md
  • challenges/closure-types/src/lib.rs
  • challenges/closure-types/tests/tests.rs

Walkthrough

This pull request updates the closure-types learning challenge to reclassify the checkout_cart closure from FnOnce to Fn. The change spans three files: the task description now specifies Fn instead of FnOnce, the public function signature is updated to require impl Fn(String) -> String for the returned closure, and the test is converted from a compile-fail check to a runtime test that verifies the closure can be invoked multiple times with different inputs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: correcting the checkout_cart closure trait from FnOnce to Fn, which aligns with the PR's primary objective.
Description check ✅ Passed The description thoroughly explains the change, provides clear rationale for the correction, and lists all modified files with explanations of what was changed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant