diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-09-03 09:57:14 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-09-03 09:57:14 +0300 |
commit | adbaf65c09550cbc4fdb6d3272d7efa33eefb069 (patch) | |
tree | b5b4b77c9857e80ef7c6f6dcc3548079186d6a91 /src | |
parent | 1827c48e73545e2fac1158814bc20b52547cfeda (diff) | |
download | subplot-adbaf65c09550cbc4fdb6d3272d7efa33eefb069.tar.gz |
refactor: use the more idiomatic Into to convert &str to String
The helper function was unnecessary baggage, written by an
inexperienced Rust programmer (i.e., me, three years ago). It's time
to let go.
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r-- | src/ast.rs | 22 |
1 files changed, 9 insertions, 13 deletions
@@ -310,18 +310,18 @@ impl YamlMetadata { fn to_map(&self) -> Map<String, MetaValue> { trace!("Creating metadata map from parsed YAML"); let mut map: Map<String, MetaValue> = Map::new(); - map.insert(s("title"), meta_string(&self.title)); + map.insert("title".into(), meta_string(&self.title)); if let Some(v) = &self.subtitle { - map.insert(s("subtitle"), meta_string(v)); + map.insert("subtitle".into(), meta_string(v)); } if let Some(v) = &self.author { - map.insert(s("author"), meta_string(v)); + map.insert("author".into(), meta_string(v)); } if let Some(v) = &self.date { - map.insert(s("date"), meta_string(v)); + map.insert("date".into(), meta_string(v)); } if let Some(v) = &self.classes { - map.insert(s("classes"), meta_strings(v)); + map.insert("classes".into(), meta_strings(v)); } if !self.impls.is_empty() { let impls = self @@ -329,26 +329,22 @@ impl YamlMetadata { .iter() .map(|(k, v)| (k.to_owned(), Box::new(meta_path_bufs(v)))) .collect(); - map.insert(s("impls"), MetaValue::MetaMap(impls)); + map.insert("impls".into(), MetaValue::MetaMap(impls)); } if let Some(v) = &self.bibliography { - map.insert(s("bibliography"), meta_path_bufs(v)); + map.insert("bibliography".into(), meta_path_bufs(v)); } if let Some(v) = &self.bindings { - map.insert(s("bindings"), meta_path_bufs(v)); + map.insert("bindings".into(), meta_path_bufs(v)); } if let Some(v) = &self.documentclass { - map.insert(s("documentclass"), meta_string(v)); + map.insert("documentclass".into(), meta_string(v)); } trace!("Created metadata map from parsed YAML"); map } } -fn s(s: &str) -> String { - s.to_string() -} - fn meta_string(s: &str) -> MetaValue { MetaValue::MetaString(s.to_string()) } |