You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, I'm writing an API library to retrieve data from an external service. I'm looking to encode certain guarantees that are satisfied by the service in my types, specifically the one I'm looking for is min/max length checks for alloc::String types as fields. For instance, a shortened version of a struct I have(extraneous fields removed) looks like this:
pubstructBid{#[facet(default = String::from("bid"))]r#type:String,// .../// The bid's description. Limited to 1024 characters.pubdescription:String,/// A shorter description for tighter spaces. Limited to 256 characters.pubshortdescription:String,// ...}
I'd like some way to ensure in code that these types also have their length limits enforced. Is this already possible?
See below for what I've envisioned this to look like:
pubstructBid{#[facet(default = String::from("bid"))]r#type:String,// .../// The bid's description. Limited to 1024 characters.#[facet(max_length = 1024)]pubdescription:String,/// A shorter description for tighter spaces. Limited to 256 characters.#[facet(max_length = 256)]pubshortdescription:String,// ...}
Note for above: While I wouldn't have a use for it, I could imagine this hypothetical API also supporting a min_length parameter as well
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, I'm writing an API library to retrieve data from an external service. I'm looking to encode certain guarantees that are satisfied by the service in my types, specifically the one I'm looking for is min/max length checks for
alloc::String
types as fields. For instance, a shortened version of a struct I have(extraneous fields removed) looks like this:I'd like some way to ensure in code that these types also have their length limits enforced. Is this already possible?
See below for what I've envisioned this to look like:
Note for above: While I wouldn't have a use for it, I could imagine this hypothetical API also supporting a
min_length
parameter as wellBeta Was this translation helpful? Give feedback.
All reactions