2019-07-03 22:31:15 +02:00
|
|
|
#[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) {
|
2019-07-03 22:31:15 +02:00
|
|
|
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());
|
2019-07-03 22:31:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$crate::stream::InputStream::from_stream(objects.boxed())
|
|
|
|
} else {
|
|
|
|
$expr
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2019-05-23 06:30:43 +02:00
|
|
|
crate use crate::cli::MaybeOwned;
|
2019-07-03 22:31:15 +02:00
|
|
|
crate use crate::commands::command::{
|
2019-08-02 21:15:07 +02:00
|
|
|
CommandAction, CommandArgs, ReturnSuccess, ReturnValue, RunnableContext,
|
2019-07-03 22:31:15 +02:00
|
|
|
};
|
2019-08-09 06:51:21 +02:00
|
|
|
crate use crate::commands::StaticCommand;
|
|
|
|
crate use crate::context::CommandRegistry;
|
2019-08-01 05:25:59 +02:00
|
|
|
crate use crate::context::{Context, SpanSource};
|
2019-05-24 21:35:22 +02:00
|
|
|
crate use crate::env::host::handle_unexpected;
|
2019-08-07 19:49:11 +02:00
|
|
|
crate use crate::env::Host;
|
2019-05-13 19:30:51 +02:00
|
|
|
crate use crate::errors::ShellError;
|
2019-08-02 21:15:07 +02:00
|
|
|
crate use crate::object::base as value;
|
2019-08-01 03:58:42 +02:00
|
|
|
crate use crate::object::meta::{Tag, Tagged, TaggedItem};
|
2019-07-13 04:18:02 +02:00
|
|
|
crate use crate::object::types::ExtractType;
|
2019-06-27 18:47:24 +02:00
|
|
|
crate use crate::object::{Primitive, Value};
|
2019-08-09 06:51:21 +02:00
|
|
|
crate use crate::parser::hir::SyntaxType;
|
2019-08-02 21:15:07 +02:00
|
|
|
crate use crate::parser::registry::Signature;
|
2019-08-07 19:49:11 +02:00
|
|
|
crate use crate::shell::filesystem_shell::FilesystemShell;
|
|
|
|
crate use crate::shell::shell_manager::ShellManager;
|
|
|
|
crate use crate::shell::value_shell::ValueShell;
|
2019-07-03 22:31:15 +02:00
|
|
|
crate use crate::stream::{InputStream, OutputStream};
|
2019-07-24 00:22:11 +02:00
|
|
|
crate use crate::traits::{HasSpan, ToDebug};
|
2019-08-01 03:58:42 +02:00
|
|
|
crate use crate::Span;
|
2019-06-22 22:46:16 +02:00
|
|
|
crate use crate::Text;
|
2019-07-03 22:31:15 +02:00
|
|
|
crate use futures::stream::BoxStream;
|
2019-07-24 00:22:11 +02:00
|
|
|
crate use futures::{FutureExt, Stream, StreamExt};
|
2019-08-03 04:17:28 +02:00
|
|
|
crate use futures_async_stream::async_stream_block;
|
2019-08-06 18:26:33 +02:00
|
|
|
#[allow(unused)]
|
2019-08-02 21:15:07 +02:00
|
|
|
crate use serde::{Deserialize, Serialize};
|
2019-05-13 19:30:51 +02:00
|
|
|
crate use std::collections::VecDeque;
|
2019-07-03 22:31:15 +02:00
|
|
|
crate use std::future::Future;
|
2019-05-23 09:23:06 +02:00
|
|
|
crate use std::sync::{Arc, Mutex};
|
2019-07-03 22:31:15 +02:00
|
|
|
|
|
|
|
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,
|
2019-07-03 22:31:15 +02:00
|
|
|
{
|
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|