-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to modify the routes list at runtime? #1517
Comments
There are a few obstacles to supporting this sort of feature. It is possible in principle, though I am not sure what exactly the costs would be and whether they align with Rocket's goals.
More broadly, several aspects of Rocket (and/or Rust) benefit greatly from things being known at compile-time or at launch-time and can be optimized accordingly. That is not to say that dynamic approaches like yours are impossible, simply more difficult to implement and/or less performant. That said, there are a few potential workarounds that come to mind that would work "inside" of Rocket's capabilities.
Off the top of my head, I don't know of the most popular Rust web frameworks having similar features - but I would be interested to know if someone else does happen to be doing this already. |
Hm, I see.
I think it would be a good compromise if it's going to be a thing. Other context-related objects are already being injected this way (I'm referring to
I think I understand. Though, just wondering (I'm still thinking like I would in another language), would something like a linked list (via
I think an approach like this would work: use std::path::PathBuf;
#[get("/plugin/<path..>")]
fn process_plugin_request(path: PathBuf) {
// [...] code required to obtain the foreign procedure and match with route subpath
ffiPluginFn(...);
} |
My (limited) understanding of Java's object model, to use your original comparison, is that every garbage-collected object has "built-in" synchronization overhead that is similar to what we would need to add here - of course, a lot of the actual performance impact depends on the specific usage patterns. My concern is not that this is a bad or too-difficult proposal in itself, but that implementing this or similar features would "undo" some of the performance benefits that are gained by using Rust/Rocket instead of another framework or language - which for some users could be the reason to use it in the first place.
One particular issue you might have missed is that one thread may try to "remove" a route that another thread(s) are running that route - so instead of I'm, personally speaking, happy to consider this sort of functionality (and even offer some guidance on how Rocket would have to change to support it), but I do expect it to be performance-sensitive enough to need significant effort in auditing and testing. |
Ah, right, I see.
Ah, right! Yeah they would be more appropriate in this context. I see your concern; it might introduce unwanted bottlenecks to request handling and routing.
I think I got it now. Well, I am not fluent enough with Rust to do it myself yet ahah Thank you for your replies; I'll try to dispatch the requests manually then. |
Rocket version: latest (I think it's 0.4.6)
Hello, I'm a novice with Rust and Rocket.
I was thinking it would be nice to have the possibility to add new routes at runtime (if it's not already possible to do so).
I'm coming from Java and the usual use-case is when deploying new servlets and serving them without reloading the application container (see modules or OSGi-related technologies). In my specific case, I'm creating my own website with Rocket to practice my Rust skills and I would prefer to just add new routes on-the-fly or replace them (maybe mimicing the common osgi path observer approach and some FFI).
I am not sure since I'm a beginner, but maybe it is possible to impl Clone for the
Rocket
trait by providing a cloneable thread-safe box (I'm thinking about something likeArc<Rocket>
).What I would like to achieve is something like these examples below.
Hypothetical "add new route" request:
Hypothetical "unregister route" request:
Thank you for your replies in advance.
The text was updated successfully, but these errors were encountered: