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:
@@ -243,6 +243,13 @@ impl InteractionForm {
|
||||
.find_map(|(field, value)| (field == name).then_some(value.as_str()))
|
||||
}
|
||||
|
||||
pub fn parse<T>(&self, name: &str) -> Option<T>
|
||||
where
|
||||
T: std::str::FromStr,
|
||||
{
|
||||
self.value(name).and_then(|value| value.parse().ok())
|
||||
}
|
||||
|
||||
pub fn values<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a str> + 'a {
|
||||
self.fields
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user