Skip to content

Provide warp::cloned to simplify passing shared services to routes#1109

Open
andyHa wants to merge 7 commits intoseanmonstar:masterfrom
andyHa:master
Open

Provide warp::cloned to simplify passing shared services to routes#1109
andyHa wants to merge 7 commits intoseanmonstar:masterfrom
andyHa:master

Conversation

@andyHa
Copy link
Copy Markdown
Contributor

@andyHa andyHa commented Dec 16, 2024

Passing shared services to routes is a very common task. Most of the time these implement Clone
as they're most probably wrapped as Arc anyway. Using with_cloneable is a bit shorter and
more concise than crate::any().map(move || value.clone()).

@seanmonstar
Copy link
Copy Markdown
Owner

Sorry, I hadn't been paying attention to the notifications here, I was way too busy with other things. I've finally gotten back to fixing up warp some.

I appreciate the goal here, and I admit I'm slightly torn. On the one hand, since warp::any().map(move || val.clone()) works, I kind of like it being the "one way". But I recognize it requires understanding several concepts that are somewhat unrelated to just "give me clones of this thing".

If I did merge something like this, I think I'd lean towards a different name. Possibly warp::cloned(val), maybe something else fluid like that. The term with is already used for wrapping filters, and cloneable is closer to Java-speak than Rust normally is. Anyways, that's my thoughts 🫣

@andyHa andyHa changed the title Provide with_cloneable to simplify passing shared services to routes Provide warp::cloned to simplify passing shared services to routes Jan 14, 2026
Before 0.4 a stream could by sent as body via
Body::wrap_stream. This has been made
private to not expose any internal workings.

With this change, replying with a stream is
possible again without exposing any
internals.
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