From 6596e7cddfc00281362c3640781f6cd6bc0b5614 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 28 Mar 2020 11:08:19 +0100 Subject: Nice string formatting --- crates/ra_syntax/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax/src/lib.rs') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index cef926ed3..f0e16dc2b 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -32,9 +32,10 @@ pub mod ast; #[doc(hidden)] pub mod fuzz; -use std::{fmt::Write, marker::PhantomData, sync::Arc}; +use std::{marker::PhantomData, sync::Arc}; use ra_text_edit::AtomTextEdit; +use stdx::format_to; use crate::syntax_node::GreenNode; @@ -115,7 +116,7 @@ impl Parse { pub fn debug_dump(&self) -> String { let mut buf = format!("{:#?}", self.tree().syntax()); for err in self.errors.iter() { - writeln!(buf, "error {:?}: {}", err.range(), err).unwrap(); + format_to!(buf, "error {:?}: {}\n", err.range(), err); } buf } @@ -296,7 +297,7 @@ fn api_walkthrough() { NodeOrToken::Node(it) => it.text().to_string(), NodeOrToken::Token(it) => it.text().to_string(), }; - buf += &format!("{:indent$}{:?} {:?}\n", " ", text, node.kind(), indent = indent); + format_to!(buf, "{:indent$}{:?} {:?}\n", " ", text, node.kind(), indent = indent); indent += 2; } WalkEvent::Leave(_) => indent -= 2, -- cgit v1.2.3