nushell/src/prelude.rs

86 lines
2.3 KiB
Rust
Raw Normal View History

#[macro_export]
macro_rules! stream {
($($expr:expr),*) => {{
let mut v = VecDeque::new();
$(
v.push_back($expr);
)*
v
}}
}
#[macro_export]
macro_rules! trace_stream {
2019-07-12 21:22:08 +02:00
(target: $target:tt, $desc:tt = $expr:expr) => {{
if log::log_enabled!(target: $target, log::Level::Trace) {
use futures::stream::StreamExt;
// Blocking is generally quite bad, but this is for debugging
// let mut local = futures::executor::LocalPool::new();
// let objects = local.run_until($expr.into_vec());
// let objects: Vec<_> = futures::executor::block_on($expr.into_vec());
let objects = $expr.values.inspect(|o| {
2019-07-12 21:22:08 +02:00
trace!(target: $target, "{} = {:#?}", $desc, o.debug());
});
$crate::stream::InputStream::from_stream(objects.boxed())
} else {
$expr
}
}};
}
2019-05-23 06:30:43 +02:00
crate use crate::cli::MaybeOwned;
crate use crate::commands::command::{
2019-07-16 09:08:35 +02:00
Command, CommandAction, CommandArgs, ReturnSuccess, ReturnValue, Sink, SinkCommandArgs,
};
crate use crate::context::{Context, SpanSource};
2019-05-24 21:35:22 +02:00
crate use crate::env::host::handle_unexpected;
crate use crate::env::{Environment, Host};
crate use crate::errors::ShellError;
2019-08-01 03:58:42 +02:00
crate use crate::object::meta::{Tag, Tagged, TaggedItem};
crate use crate::object::types::ExtractType;
2019-06-27 18:47:24 +02:00
crate use crate::object::{Primitive, Value};
crate use crate::stream::{InputStream, OutputStream};
2019-08-01 03:58:42 +02:00
crate use crate::Span;
2019-06-22 22:46:16 +02:00
crate use crate::Text;
crate use futures::stream::BoxStream;
crate use futures::Stream;
2019-06-08 00:35:07 +02:00
crate use futures::{FutureExt, StreamExt};
crate use std::collections::VecDeque;
crate use std::future::Future;
crate use std::sync::{Arc, Mutex};
pub trait FromInputStream {
fn from_input_stream(self) -> OutputStream;
}
impl<T> FromInputStream for T
where
2019-08-01 03:58:42 +02:00
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(),
}
}
}