Crates.io | inform |
lib.rs | inform |
version | |
source | src |
created_at | 2024-07-09 21:59:23.654269 |
updated_at | 2024-12-05 01:00:50.129257 |
description | Another Rust indentation formatter |
homepage | |
repository | https://github.com/ethanuppal/inform |
max_upload_size | |
id | 1297522 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
indent formatting, everywhere
inform
gives you
std::fmt::Formatter
drop-in replacement designed for formatting
structured data such as AST nodes.std::io::Write
or std::fmt::Write
with indentation.The format and I/O implementations are behind Cargo features "fmt"
and "io"
respectively, both of which are enabled by default.
Here's how you can use fmt::IndentFormatter
:
use std::fmt::{self, Write};
use inform::common::IndentWriterCommon, fmt::IndentFormatter;
struct TestIndentFormatter;
impl fmt::Display for TestIndentFormatter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut f = IndentFormatter::new(f, 2);
writeln!(f, "hello\ngoodbye")?;
f.increase_indent();
writeln!(f, "hello\ngoodbye")?;
f.decrease_indent();
writeln!(f, "hello\ngoodbye")
}
}
#[test]
fn test_indent_formatter() {
assert_eq!(
"hello\ngoodbye\n hello\n goodbye\nhello\ngoodbye\n",
TestIndentFormatter.to_string()
);
}
Here's how you can use fmt::IndentWriter
:
use std::fmt::{self, Write};
use inform::common::IndentWriterCommon, fmt::IndentWriter;
fn write_text(str: &mut String) -> fmt::Result {
let mut f = IndentWriter::new(str, 2);
writeln!(f, "hello\ngoodbye")?;
f.increase_indent();
writeln!(f, "hello\ngoodbye")?;
f.decrease_indent();
writeln!(f, "hello\ngoodbye")
}
#[test]
fn test_indent_writer() {
let mut buffer = String::new();
write_text(&mut buffer).expect("failed to format");
assert_eq!(
"hello\ngoodbye\n hello\n goodbye\nhello\ngoodbye\n",
buffer
);
}
inform
The following crates are alternatives that I found did not fit my use case.
A copy of the LGPL License is provided in the LICENSE file.