Module genco::fmt

source ·
Expand description

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§

  • Configuration to use for formatting output.
  • Helper struct to format a token stream to an underlying writer implementing fmt::Write.
  • Token stream formatter. Keeps track of everything we need to know in order to enforce genco’s indentation and whitespace rules.
  • Helper struct to format a token stream to an underlying writer implementing io::Write.
  • Helper struct to format a token stream as a vector of strings.

Enums§

Type Aliases§

  • Error for the fmt module.
  • Result type for the fmt module.