1use std::{borrow::Cow, fs::File, io::{self, Write}};
2
3pub fn find_matches(contents: &Cow<str>, from: &String) -> usize {
5 let string_matches = contents.matches(&*from).into_iter().count();
6 println!("Found {:#?} instances of {:#?}", string_matches, from);
7
8 string_matches
9}
10
11pub fn replace(contents: Cow<str>, from: &String, to: &String) -> String {
13 println!("Replacing {:?} to {:?}..", from, to);
14 contents.replace(&*from, &to)
15}
16
17pub fn create_file_and_put_contents(content_to_write: String, new_path: &String) -> io::Result<()> {
19 let mut new_file = File::create(new_path)?;
20 println!("Saving to {:?}", new_path);
21 new_file.write_all(content_to_write.as_bytes())?;
22
23 Ok(())
24}