1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::path::PathBuf;
use boolinator::Boolinator;
pub fn is_existing_path<A: AsRef<str>>(s: A) -> Result<(), String> {
PathBuf::from(s.as_ref()).exists().as_result((), format!("Not a File or Directory: {}", s.as_ref()))
}
pub fn is_file<A: AsRef<str>>(s: A) -> Result<(), String> {
PathBuf::from(s.as_ref()).is_file().as_result((), format!("Not a File: {}", s.as_ref()))
}
pub fn is_directory<A: AsRef<str>>(s: A) -> Result<(), String> {
PathBuf::from(s.as_ref()).is_dir().as_result((), format!("Not a Directory: {}", s.as_ref()))
}
pub fn is_integer<A: AsRef<str>>(s: A) -> Result<(), String> {
use std::str::FromStr;
let i : Result<i64, _> = FromStr::from_str(s.as_ref());
i.map(|_| ()).map_err(|_| format!("Not an integer: {}", s.as_ref()))
}
pub fn is_float<A: AsRef<str>>(s: A) -> Result<(), String> {
use std::str::FromStr;
let i : Result<f64, _> = FromStr::from_str(s.as_ref());
i.map(|_| ()).map_err(|_| format!("Not an float: {}", s.as_ref()))
}
pub fn is_bool<A: AsRef<str>>(s: A) -> Result<(), String> {
use std::str::FromStr;
let i : Result<bool, _> = FromStr::from_str(s.as_ref());
i.map(|_| ()).map_err(|_| format!("Not an bool: {}", s.as_ref()))
}
pub fn is_url<A: AsRef<str>>(s: A) -> Result<(), String> {
use url::Url;
Url::parse(s.as_ref()).map(|_| ()).map_err(|_| format!("Not a URL: {}", s.as_ref()))
}
pub fn is_datetime<A: AsRef<str>>(s: A) -> Result<(), String> {
crate::date::datetime_from_string(s).map(|_| ()).map_err(|e| format!("{}", e))
}
pub fn is_date<A: AsRef<str>>(s: A) -> Result<(), String> {
crate::date::date_from_string(s).map(|_| ()).map_err(|e| format!("{}", e))
}