mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 10:23:52 +01:00
cleanup
This commit is contained in:
parent
d86b808694
commit
ccb3c92287
@ -4,7 +4,6 @@ crate mod desc;
|
||||
crate mod dict;
|
||||
crate mod files;
|
||||
crate mod process;
|
||||
crate mod serialization;
|
||||
crate mod types;
|
||||
|
||||
crate use base::{Primitive, Value};
|
||||
|
@ -44,26 +44,6 @@ pub enum Primitive {
|
||||
EndOfStream,
|
||||
}
|
||||
|
||||
/*
|
||||
impl Serialize for Primitive {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match self {
|
||||
Primitive::Nothing => serializer.serialize_i32(0),
|
||||
Primitive::EndOfStream => serializer.serialize_i32(0),
|
||||
Primitive::Int(i) => serializer.serialize_i64(*i),
|
||||
Primitive::Float(OF64 { inner: f }) => serializer.serialize_f64(f.into_inner()),
|
||||
Primitive::Bytes(b) => serializer.serialize_u128(*b),
|
||||
Primitive::String(ref s) => serializer.serialize_str(s),
|
||||
Primitive::Boolean(b) => serializer.serialize_bool(*b),
|
||||
Primitive::Date(d) => serializer.serialize_str(&d.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl Primitive {
|
||||
crate fn type_name(&self) -> String {
|
||||
use Primitive::*;
|
||||
|
@ -1,117 +0,0 @@
|
||||
use crate::object::base::OF64;
|
||||
use crate::prelude::*;
|
||||
|
||||
use ordered_float::OrderedFloat;
|
||||
use serde::de::{self, Visitor};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::fmt;
|
||||
|
||||
struct OF64Visitor;
|
||||
|
||||
impl Visitor<'_> for OF64Visitor {
|
||||
type Value = OF64;
|
||||
|
||||
fn visit_f64<E>(self, value: f64) -> Result<OF64, E> {
|
||||
Ok(OF64::new(OrderedFloat(value)))
|
||||
}
|
||||
|
||||
fn visit_f32<E>(self, value: f32) -> Result<OF64, E> {
|
||||
Ok(OF64::new(OrderedFloat(value as f64)))
|
||||
}
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a float")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl<'de> Deserialize<'de> for OF64 {
|
||||
fn deserialize<D>(deserializer: D) -> Result<OF64, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_f64(OF64Visitor)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
impl Serialize for Value {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match self {
|
||||
Value::Primitive(p) => p.serialize(serializer),
|
||||
Value::Object(o) => o.serialize(serializer),
|
||||
Value::List(l) => l.serialize(serializer),
|
||||
Value::Block(b) => b.serialize(serializer),
|
||||
Value::Error(e) => e.serialize(serializer),
|
||||
Value::Filesystem => "".serialize(serializer),
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
struct ValueVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ValueVisitor {
|
||||
type Value = Value;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a shell value")
|
||||
}
|
||||
|
||||
fn visit_i32<E>(self, value: i32) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(Value::int(value))
|
||||
}
|
||||
|
||||
fn visit_i64<E>(self, value: i64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(Value::int(value))
|
||||
}
|
||||
|
||||
fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(Value::int(value))
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
// TODO: Handle overflow better
|
||||
Ok(Value::int(value as i64))
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(Value::string(value))
|
||||
}
|
||||
|
||||
fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(Value::boolean(value))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl<'de> Deserialize<'de> for Value {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_any(ValueVisitor)
|
||||
}
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user