@@ -9,24 +9,24 @@ impl SyntaxMapping {
99 SyntaxMapping(HashMap::new())
1010 }
1111
12− pub fn insert(&mut self, from: String, to: String) -> Option<String> {
13− self.0.insert(from, to)
12+ pub fn insert(&mut self, from: impl Into<String>, to: impl Into<String>) -> Option<String> {
13+ self.0.insert(from.into(), to.into())
1414 }
1515
16− pub fn replace<'a>(&self, input: &'a str) -> Cow<'a, str> {
17− let mut out = Cow::from(input);
18− if let Some(value) = self.0.get(input) {
19− out = Cow::from(value.clone())
16+ pub fn replace<'a>(&self, input: impl Into<Cow<'a, str>>) -> Cow<'a, str> {
17+ let input = input.into();
18+ match self.0.get(input.as_ref()) {
19+ Some(s) => Cow::from(s.clone()),
20+ None => input,
2021 }
21− out
2222 }
2323}
2424
2525#[test]
2626fn basic() {
2727 let mut map = SyntaxMapping::new();
28− map.insert("Cargo.lock".into(), "toml".into());
29− map.insert(".ignore".into(), ".gitignore".into());
28+ map.insert("Cargo.lock", "toml");
29+ map.insert(".ignore", ".gitignore");
3030
3131 assert_eq!("toml", map.replace("Cargo.lock"));
3232 assert_eq!("other.lock", map.replace("other.lock"));