Vic/jj change lznvqqpxrpll#18
Merged
Merged
Conversation
…uction 🧩 - Updated macro to return impl Ability instead of Box for ability construction functions. - Generalized method signatures to allow any Ability type, not just boxed trait objects. - Updated integration tests to match new API and type signatures. - Improves ergonomics and flexibility for effectful code and ability usage. Future work: - Extend macro to support more context shapes and derive HasPut for structs. - Refactor Pair usage in effect APIs for full genericity.
- Added Fx::provide_has, allowing partial context provision using HasPut/Put trait, supporting both tuples and structs. - Added tests for provide_has with struct context (i32 and String fields). - Improves ergonomics for effectful code with custom context shapes. Future work: - Extend HasPut/Put derive macros for easier struct support. - Refactor provide_left and related APIs to use HasPut for full genericity.
…ext mutation API 🧩 - Renamed Fx::provide_has to Fx::update_context for clarity and ergonomics. - Updated all tests and usages to use update_context. - Added and improved tests for struct-based context mutation and handler replacement. - This change clarifies the API semantics, making context adaptation and mutation explicit and more general. Future work: - Extend HasPut/Put derive macros for easier struct support. - Refactor related APIs for full genericity and ergonomic context adaptation.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors how abilities are returned by the macro, updates tests to match the new API, and adds a new update_context helper on Fx with accompanying tests.
- abilities_macro now returns
impl Abilityinstead ofBox<dyn Ability>and uses a genericAparameter in request methods - Integration tests in
abilities_macro_test.rsare updated to wrap returned abilities inBox::newand fix generic arguments - Introduces
update_contextinprovide.rsand adds tests inprovide_test.rsto verify context updates
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/abilities_macro/src/lib.rs | Changed ability constructors to return impl Ability and updated request method generics |
| crates/integration/tests/abilities_macro_test.rs | Wrapped ability closures in Box::new and added missing generic parameter |
| crates/fx/src/core/provide.rs | Added public update_context method on Fx |
| crates/fx/src/core/tests/provide_test.rs | Added tests for update_context and combined imports |
Comments suppressed due to low confidence (3)
crates/abilities_macro/src/lib.rs:30
- Since F is required to be Clone in the where clause, consider adding
+ Cloneto theimpl Abilityreturn type (e.g.,-> impl Ability<'f, #input_ty, #ctx_ty, #ret_ty> + Clone + 'f) so callers retain the Clone bound on the ability.
pub fn #ability_fn_ident<'f, F>(f: F) -> impl Ability<'f, #input_ty, #ctx_ty, #ret_ty> + 'f
crates/fx/src/core/provide.rs:19
- Public API methods should be documented; please add a doc comment explaining how
update_contexttransforms the context and any cloning behavior required byPut<T>.
pub fn update_context<T>(self, t: T) -> Fx<'a, S, V>
crates/abilities_macro/src/lib.rs:34
- [nitpick] The generic parameter order
< 'f, P, A>may be non-intuitive; consider reordering to< 'f, A, P>or adding a comment, so the ability typeAappears alongside its bound before the pair typeP.
pub fn #method_ident<'f, P, A>(arg: #input_ty) -> Fx<'f, P, #ret_ty>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.