Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use {crate::Value, csv::StringRecord};

pub fn string_record_to_row(record: &StringRecord) -> Vec<Value> {
	record.iter().map(csv_cell_to_value).collect()
}

fn csv_cell_to_value(cell: &str) -> Value {
	let cell = cell.to_string();
	cell.parse::<bool>()
		.map(|v| Value::Bool(v))
		.or_else(|_| cell.parse::<u64>().map(|v| Value::U64(v)))
		.or_else(|_| cell.parse::<i64>().map(|v| Value::I64(v)))
		.or_else(|_| cell.parse::<f64>().map(|v| Value::F64(v)))
		.unwrap_or_else(|_| Value::Str(cell))
}