mirror of
https://github.com/nushell/nushell.git
synced 2025-08-27 20:24:07 +02:00
Split nu-cli into nu-cli/nu-engine (#2898)
We split off the evaluation engine part of nu-cli into its own crate. This helps improve build times for nu-cli by 17% in my tests. It also helps us see a bit better what's the core engine portion vs the part specific to the interactive CLI piece. There's more than can be done here, but I think it's a good start in the right direction.
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::prelude::*;
|
||||
use futures::stream::iter;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Primitive, Type, UntaggedValue, Value};
|
||||
use nu_source::{PrettyDebug, Tag, Tagged, TaggedItem};
|
||||
use nu_source::{HasFallibleSpan, PrettyDebug, Tag, Tagged, TaggedItem};
|
||||
|
||||
pub struct InputStream {
|
||||
values: BoxStream<'static, Value>,
|
||||
@@ -174,3 +174,23 @@ impl From<Vec<Value>> for InputStream {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToInputStream {
|
||||
fn to_input_stream(self) -> InputStream;
|
||||
}
|
||||
|
||||
impl<T, U> ToInputStream for T
|
||||
where
|
||||
T: Stream<Item = U> + Send + 'static,
|
||||
U: Into<Result<nu_protocol::Value, nu_errors::ShellError>>,
|
||||
{
|
||||
fn to_input_stream(self) -> InputStream {
|
||||
InputStream::from_stream(self.map(|item| match item.into() {
|
||||
Ok(result) => result,
|
||||
Err(err) => match HasFallibleSpan::maybe_span(&err) {
|
||||
Some(span) => nu_protocol::UntaggedValue::Error(err).into_value(span),
|
||||
None => nu_protocol::UntaggedValue::Error(err).into_untagged_value(),
|
||||
},
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@@ -33,3 +33,16 @@ impl<V> Stream for InterruptibleStream<V> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Interruptible<V> {
|
||||
fn interruptible(self, ctrl_c: Arc<AtomicBool>) -> InterruptibleStream<V>;
|
||||
}
|
||||
|
||||
impl<S, V> Interruptible<V> for S
|
||||
where
|
||||
S: Stream<Item = V> + Send + 'static,
|
||||
{
|
||||
fn interruptible(self, ctrl_c: Arc<AtomicBool>) -> InterruptibleStream<V> {
|
||||
InterruptibleStream::new(self, ctrl_c)
|
||||
}
|
||||
}
|
||||
|
@@ -7,3 +7,4 @@ mod output;
|
||||
pub use input::*;
|
||||
pub use interruptible::*;
|
||||
pub use output::*;
|
||||
pub use prelude::ToOutputStream;
|
||||
|
@@ -36,7 +36,7 @@ macro_rules! trace_stream {
|
||||
);
|
||||
});
|
||||
|
||||
$crate::stream::InputStream::from_stream(objects.boxed())
|
||||
nu_stream::InputStream::from_stream(objects.boxed())
|
||||
} else {
|
||||
$expr
|
||||
}
|
||||
|
Reference in New Issue
Block a user