diff --git a/containstest/Cargo.lock b/containstest/Cargo.lock new file mode 100644 index 0000000..818a5ee --- /dev/null +++ b/containstest/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "containstest" +version = "0.1.0" diff --git a/containstest/Cargo.toml b/containstest/Cargo.toml new file mode 100644 index 0000000..e0fca19 --- /dev/null +++ b/containstest/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "containstest" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/containstest/README.md b/containstest/README.md new file mode 100644 index 0000000..6fe1428 --- /dev/null +++ b/containstest/README.md @@ -0,0 +1,3 @@ +# ContaintsTest + +Finding a way to check if any of multiple characters exist in string. diff --git a/containstest/src/main.rs b/containstest/src/main.rs new file mode 100644 index 0000000..9aa453d --- /dev/null +++ b/containstest/src/main.rs @@ -0,0 +1,13 @@ +const INVALID: &'static str = " ()[]/\"\\"; + +fn invalid(check: &str) -> bool { + check.chars().any(|char| INVALID.contains(char)) +} + +fn main() { + let str = "thisisfine"; + println!("{} - {}", str, invalid(str)); + + let str = "this is not fine"; + println!("{} - {}", str, invalid(str)); +}