[−][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:
- fmt::VecWriter - To write result into a vector.
- fmt::FmtWriter - To write the result into something implementing fmt::Write.
- fmt::IoWriter- To write the result into something implementing io::Write.
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_config = fmt::Config::from_lang::<Rust>() .with_indentation(fmt::Indentation::Space(2)); let mut formatter = w.as_formatter(fmt_config); let config = rust::Config::default(); // Default format state for Rust. let format = rust::Format::default(); tokens.format(&mut formatter, &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 |
Result | Result type for the |