Implement 'FromForm' for 'Arc<T>'.

This commit is contained in:
Sergio Benitez 2022-08-30 13:48:44 -07:00
parent cbe4dcb4b5
commit c08c39e16f
1 changed files with 22 additions and 0 deletions

View File

@ -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)
}
}