pub fn write_to_format(
messages: &[Message],
path: &str,
format: OutputFormat,
config: &OutputConfig,
) -> Result<(), ChatpackError>Expand description
Writes messages to a file in the specified format.
This is a convenience function that selects the appropriate writer based on the format enum.
§Example
use chatpack::format::{OutputFormat, write_to_format};
use chatpack::core::models::OutputConfig;
use chatpack::Message;
let messages = vec![Message::new("Alice", "Hello!")];
let config = OutputConfig::new().with_timestamps();
write_to_format(&messages, "output.csv", OutputFormat::Csv, &config)?;
write_to_format(&messages, "output.json", OutputFormat::Json, &config)?;
write_to_format(&messages, "output.jsonl", OutputFormat::Jsonl, &config)?;§Errors
Returns an error if:
- The required feature for the format is not enabled
- The file cannot be written