Add is_tag_str(&str) wrapper for is_tag(String)

This commit is contained in:
Matthias Beyer 2017-06-17 12:33:44 +02:00
parent c4d4fe9389
commit ac805dcef7

View file

@ -22,13 +22,17 @@ pub type TagSlice<'a> = &'a str;
/// validator which can be used by clap to validate that a string is a valid tag /// validator which can be used by clap to validate that a string is a valid tag
pub fn is_tag(s: String) -> Result<(), String> { pub fn is_tag(s: String) -> Result<(), String> {
is_tag_str(&s)
}
pub fn is_tag_str(s: &String) -> Result<(), String> {
use filters::filter::Filter; use filters::filter::Filter;
let is_lower = |s: &String| s.chars().all(|c| c.is_lowercase()); let is_lower = |s: &String| s.chars().all(|c| c.is_lowercase());
let no_whitespace = |s: &String| s.chars().all(|c| !c.is_whitespace()); let no_whitespace = |s: &String| s.chars().all(|c| !c.is_whitespace());
let is_alphanum = |s: &String| s.chars().all(|c| c.is_alphanumeric()); let is_alphanum = |s: &String| s.chars().all(|c| c.is_alphanumeric());
if is_lower.and(no_whitespace).and(is_alphanum).filter(&s) { if is_lower.and(no_whitespace).and(is_alphanum).filter(s) {
Ok(()) Ok(())
} else { } else {
Err(format!("The string '{}' is not a valid tag", s)) Err(format!("The string '{}' is not a valid tag", s))