18 releases

0.3.9 Jan 18, 2024
0.3.8 Jan 18, 2024
0.2.3 Jul 14, 2023
0.1.4 Jul 13, 2023

#1529 in Development tools

Download history 54/week @ 2024-08-19 63/week @ 2024-08-26 150/week @ 2024-09-02 64/week @ 2024-09-09 45/week @ 2024-09-16 156/week @ 2024-09-23 206/week @ 2024-09-30 267/week @ 2024-10-07 24/week @ 2024-10-14 192/week @ 2024-10-21 101/week @ 2024-10-28 326/week @ 2024-11-04 22/week @ 2024-11-11 17/week @ 2024-11-18 16/week @ 2024-11-25 110/week @ 2024-12-02

170 downloads per month
Used in schemat

Unlicense

31KB
808 lines

mfmt

GitHub Action Crate License

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.

Install

cargo +nightly add mfmt

Examples

#![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(),
);

Technical notes

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.

References

License

The Unlicense

No runtime deps