Skip to content

Commit

Permalink
CHECKPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis committed Sep 2, 2024
1 parent aea1875 commit c5926c6
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,42 @@ impl<'de> Deserialize<'de> for SourceFile {
/// e.g. gcc @compile_flags.txt. Because the `CompileCommand` struct is used to
/// represent both file types, we utilize a tagged union here to differentitate
/// between the two files
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum CompileArgs {
Arguments(Vec<String>),
Flags(Vec<String>),
}

impl<'de> Deserialize<'de> for CompileArgs {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[allow(dead_code)]
struct CompileArgVisitor;

impl<'de> Visitor<'de> for CompileArgVisitor {
type Value = CompileArgs;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a string representing a file path")
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: SerdeError,
{
Ok(CompileArgs::Arguments(()))
}
}

match serde_json::Value::deserialize(deserializer)? {
serde_json::Value::String(s) => Ok(SourceFile::File(PathBuf::from(s))),
_ => Err(SerdeError::custom("expected a string")),
}
}
}

/// Represents a single entry within a `compile_commands.json` file, or a compile_flags.txt file
/// Either `arguments` or `command` is required. `arguments` is preferred, as shell (un)escaping
/// is a possible source of errors.
Expand Down

0 comments on commit c5926c6

Please sign in to comment.