#[derive(Default)]
struct Validator {
name: String,
+ message: String,
}
pub trait TValidator {
fn get_name(&self) -> String;
+ fn get_message(&self) -> String;
+ fn set_message(&mut self, message: &str);
+
fn validate(&self, value: &String) -> bool;
}
String::from(&self.validator.name)
}
+ fn get_message(&self) -> String {
+ String::from(&self.validator.message)
+ }
+
+ fn set_message(&mut self, message: &str) {
+ self.validator.message = String::from(message);
+ }
+
fn validate(&self, value: &String) -> bool {
if value != "" {
true
pub fn new(name: &String) -> Self {
let mut v: ValidatorNotEmpty = Default::default();
v.validator.name = String::from(name);
+ v.validator.message = String::from("Mandatory field");
v
}
String::from(&self.validator.name)
}
+ fn get_message(&self) -> String {
+ String::from(&self.validator.message)
+ }
+
+ fn set_message(&mut self, message: &str) {
+ self.validator.message = String::from(message);
+ }
+
fn validate(&self, value: &String) -> bool {
true
}
pub fn new(name: &String, regex: &str) -> Self {
let mut v: ValidatorRegex = Default::default();
v.validator.name = String::from(name);
+ v.validator.message = String::from("Invalid value");
v.regex = String::from(regex);
v