Skip to content

Commit

Permalink
chore: add trait Send, Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
tejmagar committed Jun 9, 2024
1 parent 7f38f59 commit f81f7b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/forms/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::future::Future;

use crate::core::forms::{Files, FormData};

pub type FieldResult<T> = Box<dyn Future<Output = T> + Sync + Unpin>;
pub type FieldResult<T> = Box<dyn Future<Output = T> + Send + Sync + Unpin>;

pub trait AbstractFields {
pub trait AbstractFields: Sync + Send {
fn field_name(&self) -> FieldResult<String>;
fn validate(
&mut self,
Expand All @@ -16,7 +16,7 @@ pub trait AbstractFields {
fn wrap(&self) -> Box<dyn AbstractFields>;
}

pub type FormFields = Vec<Box<dyn AbstractFields>>;
pub type FormFields = Vec<Box<dyn AbstractFields + Sync + Send>>;

pub enum FieldError {
Message(Vec<String>),
Expand Down
12 changes: 6 additions & 6 deletions src/forms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use crate::core::request::Request;

use crate::forms::fields::AbstractFields;

pub type FormFields = Vec<Box<dyn AbstractFields>>;
pub type FormFields = Vec<Box<dyn AbstractFields + Sync + Send>>;

pub type ValidationError = HashMap<String, Vec<String>>;

pub trait FormValidator: Sized {
pub trait FormValidator: Sized + Send {
fn new() -> Self;
fn form_fields(&mut self) -> FormFields;
fn validate<'a>(
mut self,
request: &'a Request,
) -> Box<dyn Future<Output = Result<Self, ValidationError>> + Unpin + 'a>
) -> Box<dyn Future<Output = Result<Self, ValidationError>> + Sync + Send + Unpin + 'a>
where
Self: 'a,
Self: 'a, Self: Sync,
{
let request = request.clone();

Expand Down Expand Up @@ -60,8 +60,8 @@ pub trait FormValidator: Sized {
&mut self,
_: &Request,
_: &String,
_: &Box<dyn AbstractFields>,
) -> Box<dyn Future<Output = Option<Result<(), Vec<String>>>> + Sync + Unpin + 'static> {
_: &Box<dyn AbstractFields + Sync + Send>,
) -> Box<dyn Future<Output = Option<Result<(), Vec<String>>>> + Sync + Send + Unpin + 'static> {
Box::new(Box::pin(async move { None }))
}
}

0 comments on commit f81f7b9

Please sign in to comment.