Skip to main content

render_error

Function render_error 

Source
pub fn render_error(path: &Path, error: &FormatFileError) -> String
Expand description

Renders error as a human-readable diagnostic naming path, using rustc-style source snippets for a FormatFileError::Format.

I/O diagnostics end with \n. Format diagnostics preserve the source renderer’s styling and line endings. Print the returned string directly with eprint!.

  • Complexity: copies O(p) path bytes and returns O(r) rendered bytes. Additional time and space follow the source diagnostic renderer for each format error.

§Examples

use adam_fmt::{FormatFileError, render_error};
use std::{io, path::Path};

let error = FormatFileError::Io(io::Error::other("cannot read"));
let diagnostic = render_error(Path::new("sheet.adm2"), &error);
assert_eq!(diagnostic, "adam-fmt: sheet.adm2: cannot read\n");