feat(axum): parse typed interaction values
Add InteractionForm::parse for common typed field extraction and use it in example interaction handlers to avoid repeated string parsing plumbing. req: form/004 req: dx/003 req: examples/003
This commit is contained in:
@@ -117,6 +117,17 @@ fn interaction_form_parses_handle_and_fields() {
|
||||
assert_eq!(form.values("tag").collect::<Vec<_>>(), ["a", "b/c"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interaction_form_parses_typed_values() {
|
||||
// req: form/004 req: dx/003
|
||||
let form = InteractionForm::parse_urlencoded(b"__h=42&count=7&bad=nope")
|
||||
.expect("form should parse");
|
||||
|
||||
assert_eq!(form.parse::<u32>("count"), Some(7));
|
||||
assert_eq!(form.parse::<u32>("bad"), None);
|
||||
assert_eq!(form.parse::<u32>("missing"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interaction_form_requires_numeric_handle() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user