save-analysis: add a kind tag to JSON dumps

This commit is contained in:
Nick Cameron 2016-09-07 11:28:13 +12:00
parent 68d29cba95
commit 31100403fd
3 changed files with 14 additions and 1 deletions

View File

@ -16,6 +16,8 @@ use rustc_serialize::json::as_json;
use external_data::*;
use data::{VariableKind, Visibility};
use dump::Dump;
use super::Format;
// A dumper to dump a restricted set of JSON information, designed for use with
// libraries distributed without their source. Clients are likely to use type
@ -81,17 +83,25 @@ impl<'b, W: Write + 'b> Dump for JsonApiDumper<'b, W> {
#[derive(Debug, RustcEncodable)]
struct Analysis {
kind: Format,
prelude: Option<CratePreludeData>,
imports: Vec<Import>,
defs: Vec<Def>,
// These two fields are dummies so that clients can parse the two kinds of
// JSON data in the same way.
refs: Vec<()>,
macro_refs: Vec<()>,
}
impl Analysis {
fn new() -> Analysis {
Analysis {
kind: Format::JsonApi,
prelude: None,
imports: vec![],
defs: vec![],
refs: vec![],
macro_refs: vec![],
}
}
}

View File

@ -16,6 +16,7 @@ use rustc_serialize::json::as_json;
use external_data::*;
use data::VariableKind;
use dump::Dump;
use super::Format;
pub struct JsonDumper<'b, W: Write + 'b> {
output: &'b mut W,
@ -87,6 +88,7 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {
#[derive(Debug, RustcEncodable)]
struct Analysis {
kind: Format,
prelude: Option<CratePreludeData>,
imports: Vec<Import>,
defs: Vec<Def>,
@ -97,6 +99,7 @@ struct Analysis {
impl Analysis {
fn new() -> Analysis {
Analysis {
kind: Format::Json,
prelude: None,
imports: vec![],
defs: vec![],

View File

@ -766,7 +766,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String {
result
}
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, RustcEncodable)]
pub enum Format {
Csv,
Json,