1use super::AsStr;
20use crate::error::Error;
21
22pub fn apply<T: Suffix>(v: &T, (pat,): (&str,)) -> Result<(), Error> {
23 if !v.validate_suffix(pat) {
24 return Err(Error::new(format!("does not end with \"{pat}\"")));
25 }
26 Ok(())
27}
28
29pub trait Suffix {
30 fn validate_suffix(&self, pat: &str) -> bool;
31}
32
33impl<T: AsStr> Suffix for T {
34 fn validate_suffix(&self, pat: &str) -> bool {
35 self.as_str().ends_with(pat)
36 }
37}
38
39impl<T: Suffix> Suffix for Option<T> {
40 fn validate_suffix(&self, pat: &str) -> bool {
41 match self {
42 Some(value) => value.validate_suffix(pat),
43 None => true,
44 }
45 }
46}