Crates.io | mfmt |
lib.rs | mfmt |
version | 0.3.9 |
source | src |
created_at | 2023-07-10 08:40:02.302654 |
updated_at | 2024-01-18 13:56:56.459227 |
description | Meta formatter library |
homepage | |
repository | https://github.com/raviqqe/mfmt |
max_upload_size | |
id | 912724 |
size | 34,592 |
Meta formatter library in Rust.
mfmt
is a language formatter library written in Rust inspired by go fmt
. It's designed to be configuration-free and generous about styling. It simply focuses on aligning indentations.
This library is used in the following projects.
cargo +nightly add mfmt
#![feature(allocator_api)]
use indoc::indoc;
use mfmt::{Builder, format, FormatOptions, line};
use std::alloc::Global;
let builder = Builder::new(Global);
let mut string = String::new();
format(
&builder.sequence([
"{".into(),
builder.indent(builder.sequence([line(), "foo".into(), line(), "bar".into()])),
line(),
"}".into(),
]),
&mut string,
FormatOptions::new(4),
)
.unwrap();
assert_eq!(
string,
indoc!(
"
{
foo
bar
}
"
)
.trim(),
);
Unlike the Wadler's algorithm or some other formatters like prettier, mfmt
does not search the best format given source codes. For example, we do not have any "group" combinator. Instead, we rather give a formatter information to reconstruct the "best" format that is available in the original source codes.