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 b2e8ba8 commit b7533e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/forms/fields/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use tokio::sync::Mutex;

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

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

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

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

impl AbstractFields for InputField {
fn field_name(&self) -> FieldResult<String> {
fn fields(&self) -> Fields<String> {
let field_name = self.field_name.clone();
Box::new(Box::pin(async move { field_name }))
}
Expand All @@ -81,7 +82,7 @@ impl AbstractFields for InputField {
&mut self,
form_data: &mut FormData,
_: &mut Files,
) -> FieldResult<Result<(), Vec<String>>> {
) -> Fields<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 FieldResult<T> = Box<dyn Future<Output = T> + Send + Sync + Unpin>;
pub type Fields<T> = Box<dyn Future<Output = T> + Send + Sync + Unpin>;

pub trait AbstractFields: Sync + Send {
fn field_name(&self) -> FieldResult<String>;
fn fields(&self) -> Fields<String>;
fn validate(
&mut self,
form_data: &mut FormData,
files: &mut Files,
) -> FieldResult<Result<(), Vec<String>>>;
) -> Fields<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.field_name().await;
let field_name = field.fields().await;

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

0 comments on commit b7533e2

Please sign in to comment.