blob: 6c8938ebecd2884e806d5473d80cd5b63644183b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
use crate::Decimal;
use rocket::form::{self, FromFormField, ValueField};
use std::str::FromStr;
impl<'v> FromFormField<'v> for Decimal {
fn default() -> Option<Self> {
None
}
fn from_value(field: ValueField<'v>) -> form::Result<'v, Self> {
Decimal::from_str(field.value).map_err(|_| form::Error::validation("not a valid number").into())
}
}
|