fix: handle PathBuf correctly

This commit is contained in:
Edward Langley
2026-04-01 22:14:19 -07:00
parent da93145de5
commit 1d5edd2c09
4 changed files with 48 additions and 37 deletions

View File

@ -1,15 +1,17 @@
use std::path::Path;
use anyhow::{Context, Result};
use csv::ReaderBuilder;
use serde_json::Value;
/// Parse a CSV file and return records as serde_json::Value array
pub fn parse_csv(path: &str) -> Result<Vec<Value>> {
pub fn parse_csv(path: &Path) -> Result<Vec<Value>> {
let mut reader = ReaderBuilder::new()
.has_headers(true)
.flexible(true)
.trim(csv::Trim::All)
.from_path(path)
.with_context(|| format!("Failed to open CSV file: {path}"))?;
.with_context(|| format!("Failed to open CSV file: {}", path.display()))?;
// Detect if first row looks like headers (strings) or data (mixed)
let has_headers = reader.headers().is_ok();