diff options
Diffstat (limited to 'third_party/rust/rust_decimal/src/rocket.rs')
-rw-r--r-- | third_party/rust/rust_decimal/src/rocket.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/third_party/rust/rust_decimal/src/rocket.rs b/third_party/rust/rust_decimal/src/rocket.rs new file mode 100644 index 0000000000..6c8938ebec --- /dev/null +++ b/third_party/rust/rust_decimal/src/rocket.rs @@ -0,0 +1,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()) + } +} |