Skip to content

Commit 23c3012

Browse files
authored
Merge pull request #633 from kivikakk/push-rwluopptxlqw
Remove needless clones and reborrows.
2 parents 8bb81cd + c15326f commit 23c3012

File tree

7 files changed

+157
-251
lines changed

7 files changed

+157
-251
lines changed

examples/syntax_highlighter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use comrak::adapters::SyntaxHighlighterAdapter;
44
use comrak::{markdown_to_html_with_plugins, Options, Plugins};
5+
use std::borrow::Cow;
56
use std::collections::HashMap;
67
use std::fmt::{self, Write};
78

@@ -35,7 +36,7 @@ impl SyntaxHighlighterAdapter for PotatoSyntaxAdapter {
3536
fn write_pre_tag(
3637
&self,
3738
output: &mut dyn Write,
38-
attributes: HashMap<String, String>,
39+
attributes: HashMap<&'static str, Cow<str>>,
3940
) -> fmt::Result {
4041
if attributes.contains_key("lang") {
4142
write!(output, "<pre lang=\"{}\">", attributes["lang"])
@@ -47,7 +48,7 @@ impl SyntaxHighlighterAdapter for PotatoSyntaxAdapter {
4748
fn write_code_tag(
4849
&self,
4950
output: &mut dyn Write,
50-
attributes: HashMap<String, String>,
51+
attributes: HashMap<&'static str, Cow<str>>,
5152
) -> fmt::Result {
5253
if attributes.contains_key("class") {
5354
write!(output, "<code class=\"{}\">", attributes["class"])

src/adapters.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! Each plugin has to implement one of the traits available in this module.
44
5+
use std::borrow::Cow;
56
use std::collections::HashMap;
67
use std::fmt;
78

@@ -24,20 +25,20 @@ pub trait SyntaxHighlighterAdapter: Send + Sync {
2425
/// `<pre>` tag possibly with some HTML attribute pre-filled.
2526
///
2627
/// `attributes`: A map of HTML attributes provided by comrak.
27-
fn write_pre_tag(
28+
fn write_pre_tag<'s>(
2829
&self,
2930
output: &mut dyn fmt::Write,
30-
attributes: HashMap<String, String>,
31+
attributes: HashMap<&'static str, Cow<'s, str>>,
3132
) -> fmt::Result;
3233

3334
/// Generates the opening `<code>` tag. Some syntax highlighter libraries might include their own
3435
/// `<code>` tag possibly with some HTML attribute pre-filled.
3536
///
3637
/// `attributes`: A map of HTML attributes provided by comrak.
37-
fn write_code_tag(
38+
fn write_code_tag<'s>(
3839
&self,
3940
output: &mut dyn fmt::Write,
40-
attributes: HashMap<String, String>,
41+
attributes: HashMap<&'static str, Cow<'s, str>>,
4142
) -> fmt::Result;
4243
}
4344

0 commit comments

Comments
 (0)