[][src]Module genco::fmt

Code formatting utilities.

So you have a token stream and it's time to format it into a file/string/whatever? You've come to the right place!

Formatting is done through the following utilities:

Examples

The following is an example, showcasing how you can format directly to stdout.

Examples

use genco::prelude::*;
use genco::fmt;

let map = rust::import("std::collections", "HashMap");

let tokens: rust::Tokens = quote! {
    let mut m = #map::new();
    m.insert(1u32, 2u32);
};

let stdout = std::io::stdout();
let mut w = fmt::IoWriter::new(stdout.lock());

let fmt = fmt::Config::from_lang::<Rust>()
    .with_indentation(fmt::Indentation::Space(2));
let config = rust::Config::default();

// Default format state for Rust.
let format = rust::Format::default();

tokens.format(&mut w.as_formatter(&fmt), &config, &format)?;

Structs

Config

Configuration to use for formatting output.

FmtWriter

Helper struct to format a token stream to an underlying writer implementing fmt::Write.

Formatter

Token stream formatter. Keeps track of everything we need to know in order to enforce genco's indentation and whitespace rules.

IoWriter

Helper struct to format a token stream to an underlying writer implementing io::Write.

VecWriter

Helper struct to format a token stream as a vector of strings.

Enums

Indentation

Indentation configuration.

Type Definitions

Error

Error for the fmt module.

Result

Result type for the fmt module.