mirror of https://github.com/rwf2/Rocket.git
Implement 'FromForm' for 'Arc<T>'.
This commit is contained in:
parent
cbe4dcb4b5
commit
c08c39e16f
|
@ -1,6 +1,7 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use std::hash::Hash;
|
||||
use std::sync::Arc;
|
||||
|
||||
use either::Either;
|
||||
use indexmap::IndexMap;
|
||||
|
@ -906,3 +907,24 @@ impl<'v, A: FromForm<'v>, B: FromForm<'v>> FromForm<'v> for (A, B) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[crate::async_trait]
|
||||
impl<'v, T: FromForm<'v> + Sync> FromForm<'v> for Arc<T> {
|
||||
type Context = <T as FromForm<'v>>::Context;
|
||||
|
||||
fn init(opts: Options) -> Self::Context {
|
||||
T::init(opts)
|
||||
}
|
||||
|
||||
fn push_value(ctxt: &mut Self::Context, field: ValueField<'v>) {
|
||||
T::push_value(ctxt, field)
|
||||
}
|
||||
|
||||
async fn push_data(ctxt: &mut Self::Context, field: DataField<'v, '_>) {
|
||||
T::push_data(ctxt, field).await
|
||||
}
|
||||
|
||||
fn finalize(this: Self::Context) -> Result<'v, Self> {
|
||||
T::finalize(this).map(Arc::new)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue