Skip to content

About the RequestToken in server.rs #2777

Discussion options

You must be logged in to vote

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 us Rocket<Build>, Rocket<Ignite> and Rocket<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…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@limo520
Comment options

Answer selected by limo520
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants