Expand description
This crate provides the more additional macros to help you write code faster!
§Examples:
use add_macro::{ re, Display, From, FromStr };
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Display, From)]
enum Error {
#[from]
Io(std::io::Error),
#[display = "Incorrect E-mail address format"]
IncorrectEmail,
}
#[derive(Debug, Display, FromStr)]
#[display = "{value}"]
struct Email {
value: String,
}
impl Email {
fn parse(s: &str) -> Result<Self> {
let re = re!(r"^[\w\-]+@[\w\-]+\.\w+$");
if re.is_match(s) {
Ok(Self {
value: s.into(),
})
} else {
Err(Error::IncorrectEmail)
}
}
}
#[derive(Debug, Display)]
#[display = "Name: {name}, Age: {age}, E-mail: {email}"]
struct Person {
name: String,
age: u8,
email: Email,
}
impl Person {
pub fn new<S>(name: S, age: u8, email: Email) -> Self
where S: Into<String> {
Self {
name: name.into(),
age,
email,
}
}
}
fn main() -> Result<()> {
let bob = Person::new("Bob", 22, "bob@example.loc".parse()?);
println!("{bob}");
Ok(())
}
Modules§
Macros§
- This macros provides the fast creating BTreeMap object
- This macros provides the fast creating BTreeSet object
- This macros provides the fast creating VecDeque object
- This macros provides the fast creating BinaryHeap object
- This macros provides the usefull reading buffer by using io::stdin
- This macros provides the fast creating LinkedList object
- This macros provides the fast creating HashMap object
- This macros provides the fast creating Regex object
- This macros provides the fast creating HashSet object
- This macros provides the fast creating String object