rust-analyzer/crates/ide/src/markup.rs
Yuri Astrakhan e16c76e3c3 Inline all format arguments where possible
This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.

The change was automatically created with, so there are far less change
of an accidental typo.

```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2022-12-24 14:36:10 -05:00

38 lines
870 B
Rust

//! Markdown formatting.
//!
//! Sometimes, we want to display a "rich text" in the UI. At the moment, we use
//! markdown for this purpose. It doesn't feel like a right option, but that's
//! what is used by LSP, so let's keep it simple.
use std::fmt;
#[derive(Default, Debug)]
pub struct Markup {
text: String,
}
impl From<Markup> for String {
fn from(markup: Markup) -> Self {
markup.text
}
}
impl From<String> for Markup {
fn from(text: String) -> Self {
Markup { text }
}
}
impl fmt::Display for Markup {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.text, f)
}
}
impl Markup {
pub fn as_str(&self) -> &str {
self.text.as_str()
}
pub fn fenced_block(contents: &impl fmt::Display) -> Markup {
format!("```rust\n{contents}\n```").into()
}
}