Trait CodeBlock

Source
pub trait CodeBlock {
    // Required methods
    fn to_code_block(&self) -> String;
    fn to_code_block_with_language<S: AsRef<str>>(&self, language: S) -> String;
}
Expand description

An extension trait for code block transformations.

Required Methods§

Source

fn to_code_block(&self) -> String

Transforms the given text into a code block.

§Example
use markdown_composer::transforms::CodeBlock;

let text = "print(\"Hello world!\")";
let code_block = text.to_code_block();
assert_eq!(code_block, "```\nprint(\"Hello world!\")\n```");
Source

fn to_code_block_with_language<S: AsRef<str>>(&self, language: S) -> String

Transforms the given text into a code block, allowing to specify the language to use for highlighting.

§Example
use markdown_composer::transforms::CodeBlock;

let text = "print(\"Hello world!\")";
let code_block = text.to_code_block_with_language("python");
assert_eq!(code_block, "```python\nprint(\"Hello world!\")\n```");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> CodeBlock for T
where T: AsRef<str>,