Skip to content

Commit

Permalink
chore: fix trait AbstractFields
Browse files Browse the repository at this point in the history
  • Loading branch information
tejmagar committed Jun 10, 2024
1 parent b7533e2 commit 80fd8c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/forms/fields/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use tokio::sync::Mutex;
use crate::core::forms::{Files, FormData};

use crate::forms::AbstractFields;

use crate::forms::fields::Fields;
use crate::forms::fields::FieldResult;

pub enum InputFieldError<'a> {
MissingField(&'a String),
Expand Down Expand Up @@ -73,7 +72,7 @@ impl InputField {
}

impl AbstractFields for InputField {
fn fields(&self) -> Fields<String> {
fn field_name(&self) -> FieldResult<String> {
let field_name = self.field_name.clone();
Box::new(Box::pin(async move { field_name }))
}
Expand All @@ -82,7 +81,7 @@ impl AbstractFields for InputField {
&mut self,
form_data: &mut FormData,
_: &mut Files,
) -> Fields<Result<(), Vec<String>>> {
) -> FieldResult<Result<(), Vec<String>>> {
let field_name = self.field_name.clone();

let form_value;
Expand Down
6 changes: 3 additions & 3 deletions src/forms/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use std::future::Future;

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

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

pub trait AbstractFields: Sync + Send {
fn fields(&self) -> Fields<String>;
fn field_name(&self) -> FieldResult<String>;
fn validate(
&mut self,
form_data: &mut FormData,
files: &mut Files,
) -> Fields<Result<(), Vec<String>>>;
) -> FieldResult<Result<(), Vec<String>>>;
fn wrap(&self) -> Box<dyn AbstractFields>;
}

Expand Down
2 changes: 1 addition & 1 deletion src/forms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait FormValidator: Sized + Send {
let mut errors = HashMap::new();

for mut field in self.form_fields() {
let field_name = field.fields().await;
let field_name = field.field_name().await;

let result;
if let Some(custom_validate_result) =
Expand Down

0 comments on commit 80fd8c8

Please sign in to comment.