Skip to main content

format_to_string

Function format_to_string 

Source
pub fn format_to_string(source: &str, config: &Config) -> Result<String>
Expand description

Format Go source code string.

Formats a string containing Go source code and returns the formatted result. This is useful for formatting code in memory without file I/O.

§Arguments

  • source — Go source code string to format
  • config — Configuration settings for the formatter

§Returns

Returns Ok(String) with the formatted code, or an error if parsing fails.

§Examples

use woofmt::{format_to_string, config::Config};

let config = Config::default();
let source = r#"package main

func main() {
fmt.Println("Hello")
}"#;

let formatted = format_to_string(source, &config)?;
println!("{}", formatted);