From caa32e786af6f182e5b561a5087beb9997261952 Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Mon, 2 Sep 2024 21:50:51 -0400 Subject: [PATCH] finish up --- src/lib.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a68379d..3aed5a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Display}; use std::path::{Path, PathBuf}; use std::string::ToString; -use serde::de::{Deserializer, Error as SerdeError, Visitor}; +use serde::de::{self, Deserializer, Error as SerdeError, Visitor}; use serde::Deserialize; /// Represents a `compile_commands.json` file @@ -73,18 +73,21 @@ impl<'de> Deserialize<'de> for CompileArgs { formatter.write_str("a string representing a file path") } - fn visit_str(self, value: &str) -> Result + fn visit_seq(self, mut seq: A) -> Result where - E: SerdeError, + A: de::SeqAccess<'de>, { - Ok(CompileArgs::Arguments(())) + let mut args = Vec::new(); + + while let Some(arg) = seq.next_element::()? { + args.push(arg); + } + + Ok(CompileArgs::Arguments(args)) } } - match serde_json::Value::deserialize(deserializer)? { - serde_json::Value::String(s) => Ok(SourceFile::File(PathBuf::from(s))), - _ => Err(SerdeError::custom("expected a string")), - } + deserializer.deserialize_seq(CompileArgVisitor) } }