Skip to main content

format

Function format 

Source
pub fn format<Context>(
    context: Context,
    arguments: Arguments<'_, Context>,
) -> FormatResult<Formatted<Context>>
where Context: FormatContext,
Expand description

The format function takes an Arguments struct and returns the resulting formatting IR.

The Arguments instance can be created with the format_args!.

ยงExamples

Basic usage:

use ruff_formatter::prelude::*;
use ruff_formatter::{format, format_args};

let formatted = format!(SimpleFormatContext::default(), [&format_args!(token("test"))])?;
assert_eq!("test", formatted.print()?.as_code());

Please note that using format! might be preferable. Example:

use ruff_formatter::prelude::*;
use ruff_formatter::{format};

let formatted = format!(SimpleFormatContext::default(), [token("test")])?;
assert_eq!("test", formatted.print()?.as_code());