Skip to content

Commit

Permalink
finish up
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis committed Sep 3, 2024
1 parent c5926c6 commit caa32e7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,18 +73,21 @@ impl<'de> Deserialize<'de> for CompileArgs {
formatter.write_str("a string representing a file path")
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
E: SerdeError,
A: de::SeqAccess<'de>,
{
Ok(CompileArgs::Arguments(()))
let mut args = Vec::new();

while let Some(arg) = seq.next_element::<String>()? {
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)
}
}

Expand Down

0 comments on commit caa32e7

Please sign in to comment.