mirror of
https://github.com/nushell/nushell
synced 2025-01-06 02:09:10 +00:00
138b5af82b
This commit is more substantial than it looks: there was basically no real support for decimals before, and that impacted values all the way through. I also made Size contain a decimal instead of an integer (`1.6kb` is a reasonable thing to type), which impacted a bunch of code. The biggest impact of this commit is that it creates many more possible ways for valid nu types to fail to serialize as toml, json, etc. which typically can't support the full range of Decimal (or Bigint, which I also think we should support). This commit makes to-toml fallible, and a similar effort is necessary for the rest of the serializations. We also need to figure out how to clearly communicate to users what has happened, but failing to serialize to toml seems clearly superior to me than weird errors in basic math operations.
115 lines
3.4 KiB
Rust
115 lines
3.4 KiB
Rust
#[macro_export]
|
|
macro_rules! stream {
|
|
($($expr:expr),*) => {{
|
|
let mut v = VecDeque::new();
|
|
|
|
$(
|
|
v.push_back($expr);
|
|
)*
|
|
|
|
v
|
|
}}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! trace_stream {
|
|
(target: $target:tt, $desc:tt = $expr:expr) => {{
|
|
if log::log_enabled!(target: $target, log::Level::Trace) {
|
|
use futures::stream::StreamExt;
|
|
|
|
let objects = $expr.values.inspect(|o| {
|
|
trace!(target: $target, "{} = {:#?}", $desc, o.debug());
|
|
});
|
|
|
|
$crate::stream::InputStream::from_stream(objects.boxed())
|
|
} else {
|
|
$expr
|
|
}
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! trace_out_stream {
|
|
(target: $target:tt, source: $source:expr, $desc:tt = $expr:expr) => {{
|
|
if log::log_enabled!(target: $target, log::Level::Trace) {
|
|
use futures::stream::StreamExt;
|
|
|
|
let source = $source.clone();
|
|
|
|
let objects = $expr.values.inspect(move |o| {
|
|
trace!(target: $target, "{} = {}", $desc, o.debug(&source));
|
|
});
|
|
|
|
$crate::stream::OutputStream::new(objects)
|
|
} else {
|
|
$expr
|
|
}
|
|
}};
|
|
}
|
|
|
|
pub(crate) use crate::cli::MaybeOwned;
|
|
pub(crate) use crate::commands::command::{
|
|
CallInfo, CommandAction, CommandArgs, ReturnSuccess, ReturnValue, RunnableContext,
|
|
};
|
|
pub(crate) use crate::commands::PerItemCommand;
|
|
pub(crate) use crate::commands::RawCommandArgs;
|
|
pub(crate) use crate::context::CommandRegistry;
|
|
pub(crate) use crate::context::{Context, SpanSource};
|
|
pub(crate) use crate::env::host::handle_unexpected;
|
|
pub(crate) use crate::env::Host;
|
|
pub(crate) use crate::errors::ShellError;
|
|
pub(crate) use crate::object::base as value;
|
|
pub(crate) use crate::object::meta::{Tag, Tagged, TaggedItem};
|
|
pub(crate) use crate::object::types::ExtractType;
|
|
pub(crate) use crate::object::{Primitive, Value};
|
|
pub(crate) use crate::parser::hir::SyntaxType;
|
|
pub(crate) use crate::parser::parse::parser::Number;
|
|
pub(crate) use crate::parser::registry::Signature;
|
|
pub(crate) use crate::shell::filesystem_shell::FilesystemShell;
|
|
pub(crate) use crate::shell::shell_manager::ShellManager;
|
|
pub(crate) use crate::shell::value_shell::ValueShell;
|
|
pub(crate) use crate::stream::{InputStream, OutputStream};
|
|
pub(crate) use crate::traits::{HasSpan, ToDebug};
|
|
pub(crate) use crate::Span;
|
|
pub(crate) use crate::Text;
|
|
pub(crate) use futures::stream::BoxStream;
|
|
pub(crate) use futures::{FutureExt, Stream, StreamExt};
|
|
pub(crate) use futures_async_stream::async_stream_block;
|
|
pub(crate) use num_traits::cast::{FromPrimitive, ToPrimitive};
|
|
pub(crate) use rust_decimal::Decimal;
|
|
#[allow(unused)]
|
|
pub(crate) use serde::{Deserialize, Serialize};
|
|
pub(crate) use std::collections::VecDeque;
|
|
pub(crate) use std::future::Future;
|
|
pub(crate) use std::sync::{Arc, Mutex};
|
|
|
|
pub trait FromInputStream {
|
|
fn from_input_stream(self) -> OutputStream;
|
|
}
|
|
|
|
impl<T> FromInputStream for T
|
|
where
|
|
T: Stream<Item = Tagged<Value>> + Send + 'static,
|
|
{
|
|
fn from_input_stream(self) -> OutputStream {
|
|
OutputStream {
|
|
values: self.map(ReturnSuccess::value).boxed(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait ToOutputStream {
|
|
fn to_output_stream(self) -> OutputStream;
|
|
}
|
|
|
|
impl<T, U> ToOutputStream for T
|
|
where
|
|
T: Stream<Item = U> + Send + 'static,
|
|
U: Into<ReturnValue>,
|
|
{
|
|
fn to_output_stream(self) -> OutputStream {
|
|
OutputStream {
|
|
values: self.map(|item| item.into()).boxed(),
|
|
}
|
|
}
|
|
}
|