My application uses Rocket.rs (version 0.5-rc
) which is trying to parse forms submitted by the client.
Using Rocket has been very convenient, being able to parse structs with traits FromForm
straight from GET queries and POST forms. This trait allows for Option
parameters to default to None
values if no keys are provided.
Long story short, we have the following situation:
struct MyDataForm {
line_one: Option<String>
line_two: Option<Option<String>
}
We have a data type which represents a query to the server. In certain endpoints (such as searches) we are okay with optional parameters, so we wrap an Option
around all struct members.
However, in some places like POST, we want to be "strict" and only allow the secondary Option
to be respected. We are trying to share MyDataForm
across both POST and GET requests to avoid having to redefine more structs than necessary, especially if they share similar structures.
In doing so, I am trying to determine:
How can we tell during runtime or build time that a certain parameter has a type of
Option<Option<*>>
?
We have a uniform type defined by bson::Document
(doc) which allows us to iterate through values so we can, during runtime, dismiss nulled parameters (via string encodings of struct entry names and Bson::Null
checks) whose values are not set if and only if the entry contain types of Option<Option<*>>
.
Any feedback or ideas are much appreciated. Thank you.