rbatis_codegen/
ops_string.rs1use crate::ops::StrMethods;
2use rbs::Value;
3
4macro_rules! impl_str_methods {
5 ($($ty:ty),* $(,)?) => {
6 $(
7 impl StrMethods for $ty {
8 fn contains_str(self, value: &str) -> bool {
9 self.as_str().unwrap_or_default().contains(value)
10 }
11
12 fn starts_with(self, value: &str) -> bool {
13 self.as_str().unwrap_or_default().starts_with(value)
14 }
15
16 fn ends_with(self, value: &str) -> bool {
17 self.as_str().unwrap_or_default().ends_with(value)
18 }
19 }
20 )*
21 };
22}
23
24impl_str_methods!(Value, &Value, &&Value);
25
26#[cfg(test)]
27mod test {
28 use crate::ops::StrMethods;
29 use rbs::Value;
30
31 #[test]
32 fn test_str_methods() {
33 let value = Value::String("hello world".to_string());
34 assert!((&value).contains_str("world"));
35 assert!((&value).starts_with("hello"));
36 assert!((&&value).ends_with("world"));
37 assert!(!Value::Null.contains_str("world"));
38 }
39}