1use std::{path::PathBuf, str::FromStr};
2
3use crate::Error;
4
5pub trait Parse: Sized {
7 fn parse(string: &str) -> Result<Self, Error>;
9}
10
11impl Parse for bool {
12 fn parse(string: &str) -> Result<Self, Error> {
13 Self::from_str(string).map_err(Error::from)
14 }
15}
16
17macro_rules! impl_parse_for_int_type {
18 ($($int_type:ty),+ $(,)?) => {
19 $(
20 impl Parse for $int_type {
21 fn parse(string: &str) -> Result<Self, Error> {
22 Self::from_str(string).map_err(Error::from)
23 }
24 }
25 )+
26 }
27}
28impl_parse_for_int_type![i8, i16, i32, i64, i128, u8, u16, u32, u64, u128];
29
30impl Parse for String {
31 fn parse(string: &str) -> Result<Self, Error> {
32 Ok(string.to_string())
33 }
34}
35
36impl Parse for PathBuf {
37 fn parse(string: &str) -> Result<Self, Error> {
38 Ok(PathBuf::from(string))
39 }
40}