mirror of
https://github.com/nushell/nushell.git
synced 2025-04-11 23:08:20 +02:00
68 lines
1.5 KiB
Rust
68 lines
1.5 KiB
Rust
#[macro_export]
|
|
macro_rules! return_err {
|
|
($expr:expr) => {
|
|
match $expr {
|
|
Err(_) => return,
|
|
Ok(expr) => expr,
|
|
};
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! stream {
|
|
($($expr:expr),*) => {{
|
|
let mut v = VecDeque::new();
|
|
|
|
$(
|
|
v.push_back($expr);
|
|
)*
|
|
|
|
v
|
|
}}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! trace_out_stream {
|
|
(target: $target:tt, $desc:tt = $expr:expr) => {{
|
|
if log::log_enabled!(target: $target, log::Level::Trace) {
|
|
let objects = $expr.inspect(move |o| {
|
|
trace!(
|
|
target: $target,
|
|
"{} = {}",
|
|
$desc,
|
|
match o {
|
|
Err(err) => format!("{:?}", err),
|
|
Ok(value) => value.display(),
|
|
}
|
|
);
|
|
});
|
|
|
|
$crate::stream::OutputStream::new(objects)
|
|
} else {
|
|
$expr
|
|
}
|
|
}};
|
|
}
|
|
|
|
pub(crate) use std::collections::VecDeque;
|
|
pub(crate) use std::sync::Arc;
|
|
|
|
pub(crate) use crate::{InputStream, OutputStream};
|
|
|
|
#[allow(clippy::wrong_self_convention)]
|
|
pub trait ToOutputStream {
|
|
fn to_output_stream(self) -> OutputStream;
|
|
}
|
|
|
|
impl<T, U> ToOutputStream for T
|
|
where
|
|
T: Iterator<Item = U> + Send + Sync + 'static,
|
|
U: Into<nu_protocol::ReturnValue>,
|
|
{
|
|
fn to_output_stream(self) -> OutputStream {
|
|
OutputStream {
|
|
values: Box::new(self.map(|item| item.into())),
|
|
}
|
|
}
|
|
}
|