Skip to content

Replace Rc<Cell> builders with mutable references - #257

Closed
FalkWoldmann wants to merge 2 commits into
masterfrom
breakage_mut_ref
Closed

FalkWoldmann wants to merge 2 commits into
masterfrom
breakage_mut_ref

Conversation

@FalkWoldmann

Copy link
Copy Markdown
Member

Refactor When and rule builder APIs to mutate configs in place via &mut references, removing Rc<Cell> plumbing across proxy/server setup paths and deleting the now-unused update_cell helper.

Not sure if this would break usage. imo the risk of breakage is quite small but I need to ponder on it

Refactor `When` and rule builder APIs to mutate configs in place via
`&mut` references, removing `Rc<Cell>` plumbing across proxy/server
setup paths and deleting the now-unused `update_cell` helper.
@FalkWoldmann
FalkWoldmann marked this pull request as ready for review September 28, 2026 03:36
@alexliesenfeld

alexliesenfeld commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

I would like to avoid breaking user code, what do you think, is it worth it? I ran a could of AI-based reviewed to estimate how large the impact is and it seems that it can break quite a few cases that are not obvious at first.

Like these:

Existing usage What changes
A helper with another borrowed input: fn with_path(w: When, path: &str) -> When The return lifetime becomes ambiguous. The builder lifetime needs to be named separately from the input data’s lifetime.
A helper accepting multiple builders: fn configure(w: When, t: Then) -> (When, Then) Returning either or both builders requires explicit lifetime relationships.
A method on a fixture: fn apply(&self, w: When) -> When Lifetime elision associates the returned builder with self. The method must explicitly return the input builder’s lifetime.
An async helper: async fn configure(w: When) Now requires When<'_> or a named lifetime, even if it does not return the builder.
A helper returning a reference: fn inspect(w: &When) -> &When Must distinguish the reference’s lifetime from the builder’s internal lifetime.
Builder fields, aliases and enum variants: struct Setup { when: When } Lifetime parameters propagate through these types and their consumers.
Extension trait implementations: impl RequestExt for When The implementation must specify a lifetime, for example When<'_>.
Generic bounds and defaults: T: Into<When> or struct Pending<B = When> Need lifetime-aware declarations. Some generic defaults need restructuring.
Associated output types: type Output = When A fixed output type cannot represent builders borrowing for arbitrary input lifetimes. The surrounding trait or implementing type may need redesign.
Reusable local transformation closures: let common = |w: When| w.path("/") Can fail lifetime inference. A named function or an appropriate callback type supplies the required relationship.
Method items used as callbacks: let common: fn(When) -> When = When::any_request The method item is insufficiently general over lifetimes. A wrapping closure works.
Certain .and(...) compositions Method items, temporary storage in an enclosing Option, and returning a captured builder can fail. Several of these restrictions are avoidable within this PR.
Returning impl Trait that captures a builder In Rust 2021, returned closures, futures and other opaque values can require explicit lifetime capture bounds. Some of these examples remain valid unchanged in Rust 2024.
Returning a boxed custom trait object containing a builder, such as Box<dyn Step> The default 'static object lifetime becomes incompatible. Often fixable with an explicit shorter lifetime, if the surrounding API permits it.
Passing a builder through an existing 'static callback or future API A closure capturing the builder no longer satisfies the bound, even when the API executes it immediately.
Any storage or inspection: Box<dyn Any> or &dyn Any Fails because Any requires 'static. Adding a lifetime annotation to the trait object does not remove that requirement.
Moving a builder outside a registration callback Outer variables, channels and thread-local storage can no longer receive those builders. Keeping the server alive does not help.
Staging forwarding/proxy matchers outside the nested .filter(...) callback Fails even while remaining inside the outer rule configuration callback. This previously worked and affected the resulting rule.
Direct access to the public recording config field Cell::take/set, Rc operations and generic cloning of the field break. Mutation through &RecordingRuleBuilder also needs adjustment.
Standalone recording-builder factories An owned factory using RecordingRuleBuilder { config: Default::default() } stops working. The builder now requires backing storage elsewhere.
Multiple recording builders sharing a configuration Constructing another builder with config: rule.config.clone() stops working. Exclusive borrowing replaces the shared handles.
Code using #![deny(elided_lifetimes_in_paths)] Otherwise accepted shorthand becomes a compilation error and needs explicit lifetimes.

@FalkWoldmann

Copy link
Copy Markdown
Member Author

superseded by #320

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