提交 31100403 编写于 作者: N Nick Cameron

save-analysis: add a `kind` tag to JSON dumps

上级 68d29cba
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
use external_data::*; use external_data::*;
use data::{VariableKind, Visibility}; use data::{VariableKind, Visibility};
use dump::Dump; use dump::Dump;
use super::Format;
// A dumper to dump a restricted set of JSON information, designed for use with // 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 // libraries distributed without their source. Clients are likely to use type
...@@ -81,17 +83,25 @@ fn crate_prelude(&mut self, data: CratePreludeData) { ...@@ -81,17 +83,25 @@ fn crate_prelude(&mut self, data: CratePreludeData) {
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
struct Analysis { struct Analysis {
kind: Format,
prelude: Option<CratePreludeData>, prelude: Option<CratePreludeData>,
imports: Vec<Import>, imports: Vec<Import>,
defs: Vec<Def>, 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 { impl Analysis {
fn new() -> Analysis { fn new() -> Analysis {
Analysis { Analysis {
kind: Format::JsonApi,
prelude: None, prelude: None,
imports: vec![], imports: vec![],
defs: vec![], defs: vec![],
refs: vec![],
macro_refs: vec![],
} }
} }
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
use external_data::*; use external_data::*;
use data::VariableKind; use data::VariableKind;
use dump::Dump; use dump::Dump;
use super::Format;
pub struct JsonDumper<'b, W: Write + 'b> { pub struct JsonDumper<'b, W: Write + 'b> {
output: &'b mut W, output: &'b mut W,
...@@ -87,6 +88,7 @@ fn inheritance(&mut self, _data: InheritanceData) {} ...@@ -87,6 +88,7 @@ fn inheritance(&mut self, _data: InheritanceData) {}
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
struct Analysis { struct Analysis {
kind: Format,
prelude: Option<CratePreludeData>, prelude: Option<CratePreludeData>,
imports: Vec<Import>, imports: Vec<Import>,
defs: Vec<Def>, defs: Vec<Def>,
...@@ -97,6 +99,7 @@ struct Analysis { ...@@ -97,6 +99,7 @@ struct Analysis {
impl Analysis { impl Analysis {
fn new() -> Analysis { fn new() -> Analysis {
Analysis { Analysis {
kind: Format::Json,
prelude: None, prelude: None,
imports: vec![], imports: vec![],
defs: vec![], defs: vec![],
......
...@@ -766,7 +766,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String { ...@@ -766,7 +766,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String {
result result
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug, RustcEncodable)]
pub enum Format { pub enum Format {
Csv, Csv,
Json, Json,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册