Skip to content

add ServiceBuilder::boxed_clone_sync helper#804

Merged
seanmonstar merged 1 commit intotower-rs:masterfrom
jlizen:master
Dec 20, 2024
Merged

add ServiceBuilder::boxed_clone_sync helper#804
seanmonstar merged 1 commit intotower-rs:masterfrom
jlizen:master

Conversation

@jlizen
Copy link
Contributor

@jlizen jlizen commented Dec 19, 2024

As requested in: #777

Adding the ServiceBuilder::boxed_clone_sync() method to match boxed_clone and boxed().

Note that in this case, I used the named, BoxCloneSyncServiceLayer, rather than the layer fn returned by BoxedCloneSyncService::layer(). I don't really see a good reason to prefer the latter. I think the reason that other helpers use that, is historical (named layer didn't exist yet).

Probably we should migrate everything over, but that seems likely to be a breaking change so I held off. Glad to cut an issue on that if you concur.

The only testing was via a doctest. This matches the other helper.

@jlizen jlizen force-pushed the master branch 3 times, most recently from 8bd56ed to ac861f9 Compare December 19, 2024 01:41
@jlizen
Copy link
Contributor Author

jlizen commented Dec 20, 2024

This is a quickie if you have a minute @seanmonstar , you have context on this from #777

@seanmonstar seanmonstar merged commit 34a6951 into tower-rs:master Dec 20, 2024
where
L: Layer<S> + Send + Sync + 'static,
L::Service: Service<R> + Clone + Send + Sync + 'static,
<L::Service as Service<R>>::Future: Send + Sync + 'static,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlizen Before this arrived in 0.5.3 I had written my own boxed_clone_sync() which had looser constraints, based on how BoxCloneSyncService is defined:

<L::Service as Service<R>>::Future: Send + 'static,

Note: The future doesn't need to be Sync.

I'd like to switch to use this ServiceBuilder helper, but my existing code won't compile because I'm doing a bunch of stuff with axum responses and the futures are Send (but not Sync).

I'm happy to stay with my current approach, but I thought I'd ask if there's a reason why this helper requires the Future to be Sync.

Copy link
Contributor Author

@jlizen jlizen Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a compelling reason to keep the tight bounds, given that the service itself doesn't put the Sync bounds on the future. Seems worth cutting a PR to loosen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please send a PR. Also please use the issues or discussions section for bringing up stuff like this, comments on old PRs are much less likely to be seen.

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.

4 participants