fix(closure-types): correct checkout_cart trait from FnOnce to Fn#184
fix(closure-types): correct checkout_cart trait from FnOnce to Fn#184juliusjulyp wants to merge 1 commit into
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis pull request updates the closure-types learning challenge to reclassify the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
What
Corrects the closure trait label for
checkout_cartin the closure-typeschallenge from
FnOncetoFn.Why
checkout_cartcaptures nothing from the environment. The String itoperates on is passed as a parameter, not captured. A closure only becomes
FnOncewhen 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 Fnsrc/lib.rs— corrected return type annotation from FnOnce to Fntests/tests.rs— removed test enforcing wrong FnOnce behavior,added test_checkout_cart_multiple_calls confirming correct Fn semantics