Remove more dead code and clean up JSON

This commit is contained in:
Yehuda Katz 2019-07-12 19:18:02 -07:00
parent 7c2a1c619e
commit 6bf55c0f1e
10 changed files with 20 additions and 32 deletions

View File

@ -1,4 +1,4 @@
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*;
use std::collections::HashMap;

View File

@ -1,5 +1,5 @@
use crate::object::base::OF64;
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*;
fn convert_json_value_to_nu_value(v: &serde_hjson::Value, span: impl Into<Span>) -> Spanned<Value> {

View File

@ -1,5 +1,5 @@
use crate::object::base::OF64;
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*;
fn convert_toml_value_to_nu_value(v: &toml::Value, span: impl Into<Span>) -> Spanned<Value> {

View File

@ -1,4 +1,4 @@
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*;
fn from_node_to_value<'a, 'd>(

View File

@ -1,5 +1,5 @@
use crate::object::base::OF64;
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*;
fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, span: impl Into<Span>) -> Spanned<Value> {

View File

@ -45,15 +45,17 @@ pub fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
let name_span = args.name_span;
Ok(out
.values
.map(move |a| match serde_json::to_string(&a) {
Ok(x) => {
ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span))
}
Err(_) => Err(ShellError::maybe_labeled_error(
"Can not convert to JSON string",
"can not convert piped data to JSON string",
name_span,
)),
})
.map(
move |a| match serde_json::to_string(&value_to_json_value(&a)) {
Ok(x) => {
ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span))
}
Err(_) => Err(ShellError::maybe_labeled_error(
"Can not convert to JSON string",
"can not convert piped data to JSON string",
name_span,
)),
},
)
.to_output_stream())
}

View File

@ -72,20 +72,6 @@ impl PartialEq<Value> for Dictionary {
}
impl Dictionary {
crate fn add(&mut self, name: impl Into<String>, value: impl Into<Spanned<Value>>) {
self.entries.insert(name.into(), value.into());
}
crate fn copy_dict(&self) -> Dictionary {
let mut out = Dictionary::default();
for (key, value) in self.entries.iter() {
out.add(key.clone(), value.clone());
}
out
}
pub fn get_data(&'a self, desc: &String) -> MaybeOwned<'a, Value> {
match self.entries.get(desc) {
Some(v) => MaybeOwned::Borrowed(v),

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError;
use crate::object::{Dictionary, SpannedDictBuilder, Value};
use crate::object::{SpannedDictBuilder, Value};
use crate::prelude::*;
#[derive(Debug)]

View File

@ -1,7 +1,7 @@
use crate::Text;
use derive_new::new;
use getset::Getters;
use serde::{Serialize, Serializer};
use serde::Serialize;
use serde_derive::Deserialize;
#[derive(

View File

@ -40,7 +40,7 @@ crate use crate::context::Context;
crate use crate::env::host::handle_unexpected;
crate use crate::env::{Environment, Host};
crate use crate::errors::ShellError;
crate use crate::object::types::{ExtractType, Type};
crate use crate::object::types::ExtractType;
crate use crate::object::{Primitive, Value};
crate use crate::parser::{Span, Spanned, SpannedItem};
crate use crate::stream::{InputStream, OutputStream};