json_gettext/key_copy/rocket_feature/
mod.rs1use std::str::FromStr;
2
3use rocket::{
4 form::{self, FromFormField, ValueField},
5 request::FromParam,
6};
7
8use super::Key;
9
10#[rocket::async_trait]
11impl<'v> FromFormField<'v> for Key {
12 fn from_value(field: ValueField<'v>) -> form::Result<'v, Self> {
13 Ok(Key::from_str(field.value).map_err(form::Error::custom)?)
14 }
15}
16
17#[cfg(feature = "locale")]
18impl<'a> FromParam<'a> for Key {
19 type Error = crate::LanguageIdentifierError;
20
21 #[inline]
22 fn from_param(v: &'a str) -> Result<Self, Self::Error> {
23 Key::from_str(v)
24 }
25}
26
27#[cfg(any(feature = "language", feature = "region"))]
28impl<'a> FromParam<'a> for Key {
29 type Error = crate::ParserError;
30
31 #[inline]
32 fn from_param(v: &'a str) -> Result<Self, Self::Error> {
33 Key::from_str(v)
34 }
35}