About the RequestToken in server.rs #2777
-
I see there is a RequestToken in server.rs, and it's clear enough because of the note.
let mut data = Data::from(&mut h_body);
let token: RequestToken = rocket.preprocess_request(&mut req, &mut data).await;
let mut response = rocket.dispatch(token, &req, data).await;
let upgrade = response.take_upgrade(req.headers().get("upgrade")); But it's strange, and I have never done that myself. Is it really possible without RequestToken? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The goal here, as you note, is to enforce execution of one method before the other with the type-system. That is, if you don't call one method before the other, the program shouldn't compile. This token mechanism is one way to largely enforce this (there are ways to circumvent it, but you'd likely need to do so willingly), but there are others. Notably, there's the use of type state, which is also employed by Rocket through the existence of |
Beta Was this translation helpful? Give feedback.
The goal here, as you note, is to enforce execution of one method before the other with the type-system. That is, if you don't call one method before the other, the program shouldn't compile. This token mechanism is one way to largely enforce this (there are ways to circumvent it, but you'd likely need to do so willingly), but there are others. Notably, there's the use of type state, which is also employed by Rocket through the existence of
Phase
which gives usRocket<Build>
,Rocket<Ignite>
andRocket<Orbit>
that must be created in that order through methods that Rocket exposes. Unlike the token mechanism, the type state mechanism infects the struct's type signature. In return it allows t…