Enum nu_protocol::PipelineData
source · pub enum PipelineData {
Value(Value, Option<PipelineMetadata>),
ListStream(ListStream, Option<PipelineMetadata>),
ExternalStream {
stdout: Option<RawStream>,
stderr: Option<RawStream>,
exit_code: Option<ListStream>,
span: Span,
metadata: Option<PipelineMetadata>,
trim_end_newline: bool,
},
Empty,
}
Expand description
The foundational abstraction for input and output to commands
This represents either a single Value or a stream of values coming into the command or leaving a command.
A note on implementation:
We’ve tried a few variations of this structure. Listing these below so we have a record.
-
We tried always assuming a stream in Nushell. This was a great 80% solution, but it had some rough edges. Namely, how do you know the difference between a single string and a list of one string. How do you know when to flatten the data given to you from a data source into the stream or to keep it as an unflattened list?
-
We tried putting the stream into Value. This had some interesting properties as now commands “just worked on values”, but lead to a few unfortunate issues.
The first is that you can’t easily clone Values in a way that felt largely immutable. For example, if you cloned a Value which contained a stream, and in one variable drained some part of it, then the second variable would see different values based on what you did to the first.
To make this kind of mutation thread-safe, we would have had to produce a lock for the stream, which in practice would have meant always locking the stream before reading from it. But more fundamentally, it felt wrong in practice that observation of a value at runtime could affect other values which happen to alias the same stream. By separating these, we don’t have this effect. Instead, variables could get concrete list values rather than streams, and be able to view them without non-local effects.
- A balance of the two approaches is what we’ve landed on: Values are thread-safe to pass, and we can stream them into any sources. Streams are still available to model the infinite streams approach of original Nushell.
Variants§
Value(Value, Option<PipelineMetadata>)
ListStream(ListStream, Option<PipelineMetadata>)
ExternalStream
Empty
Implementations§
source§impl PipelineData
impl PipelineData
pub fn new_with_metadata( metadata: Option<PipelineMetadata>, span: Span ) -> PipelineData
sourcepub fn new_external_stream_with_only_exit_code(exit_code: i64) -> PipelineData
pub fn new_external_stream_with_only_exit_code(exit_code: i64) -> PipelineData
create a PipelineData::ExternalStream
with proper exit_code
It’s useful to break running without raising error at user level.
pub fn empty() -> PipelineData
pub fn metadata(&self) -> Option<PipelineMetadata>
pub fn set_metadata(self, metadata: Option<PipelineMetadata>) -> Self
pub fn is_nothing(&self) -> bool
pub fn into_value(self, span: Span) -> Value
sourcepub fn write_to_out_dests(
self,
engine_state: &EngineState,
stack: &mut Stack
) -> Result<PipelineData, ShellError>
pub fn write_to_out_dests( self, engine_state: &EngineState, stack: &mut Stack ) -> Result<PipelineData, ShellError>
Writes all values or redirects all output to the current OutDest
s in stack
.
For OutDest::Pipe
and OutDest::Capture
, this will return the PipelineData
as is
without consuming input and without writing anything.
For the other OutDest
s, the given PipelineData
will be completely consumed
and PipelineData::Empty
will be returned.
pub fn drain(self) -> Result<(), ShellError>
pub fn drain_with_exit_code(self) -> Result<i64, ShellError>
sourcepub fn into_iter_strict(
self,
span: Span
) -> Result<PipelineIterator, ShellError>
pub fn into_iter_strict( self, span: Span ) -> Result<PipelineIterator, ShellError>
Try convert from self into iterator
It returns Err if the self
cannot be converted to an iterator.
pub fn into_interruptible_iter( self, ctrlc: Option<Arc<AtomicBool>> ) -> PipelineIterator ⓘ
pub fn collect_string( self, separator: &str, config: &Config ) -> Result<String, ShellError>
sourcepub fn collect_string_strict(
self,
span: Span
) -> Result<(String, Span, Option<PipelineMetadata>), ShellError>
pub fn collect_string_strict( self, span: Span ) -> Result<(String, Span, Option<PipelineMetadata>), ShellError>
Retrieves string from pipeline data.
As opposed to collect_string
this raises error rather than converting non-string values.
The span
will be used if ListStream
is encountered since it doesn’t carry a span.
pub fn follow_cell_path( self, cell_path: &[PathMember], head: Span, insensitive: bool ) -> Result<Value, ShellError>
pub fn upsert_cell_path( &mut self, cell_path: &[PathMember], callback: Box<dyn FnOnce(&Value) -> Value>, head: Span ) -> Result<(), ShellError>
sourcepub fn map<F>(
self,
f: F,
ctrlc: Option<Arc<AtomicBool>>
) -> Result<PipelineData, ShellError>
pub fn map<F>( self, f: F, ctrlc: Option<Arc<AtomicBool>> ) -> Result<PipelineData, ShellError>
Simplified mapper to help with simple values also. For full iterator support use .into_iter()
instead
sourcepub fn flat_map<U, F>(
self,
f: F,
ctrlc: Option<Arc<AtomicBool>>
) -> Result<PipelineData, ShellError>where
Self: Sized,
U: IntoIterator<Item = Value> + 'static,
<U as IntoIterator>::IntoIter: 'static + Send,
F: FnMut(Value) -> U + 'static + Send,
pub fn flat_map<U, F>(
self,
f: F,
ctrlc: Option<Arc<AtomicBool>>
) -> Result<PipelineData, ShellError>where
Self: Sized,
U: IntoIterator<Item = Value> + 'static,
<U as IntoIterator>::IntoIter: 'static + Send,
F: FnMut(Value) -> U + 'static + Send,
Simplified flatmapper. For full iterator support use .into_iter()
instead
pub fn filter<F>( self, f: F, ctrlc: Option<Arc<AtomicBool>> ) -> Result<PipelineData, ShellError>
sourcepub fn check_external_failed(self) -> (Self, bool)
pub fn check_external_failed(self) -> (Self, bool)
Try to catch the external stream exit status and detect if it failed.
This is useful for external commands with semicolon, we can detect errors early to avoid commands after the semicolon running.
Returns self
and a flag that indicates if the external stream run failed. If self
is
not PipelineData::ExternalStream
, the flag will be false
.
Currently this will consume an external stream to completion.
sourcepub fn try_expand_range(self) -> Result<PipelineData, ShellError>
pub fn try_expand_range(self) -> Result<PipelineData, ShellError>
Try to convert Value from Value::Range to Value::List.
This is useful to expand Value::Range into array notation, specifically when
converting to json
or to nuon
.
1..3 | to XX -> [1,2,3]
sourcepub fn print(
self,
engine_state: &EngineState,
stack: &mut Stack,
no_newline: bool,
to_stderr: bool
) -> Result<i64, ShellError>
pub fn print( self, engine_state: &EngineState, stack: &mut Stack, no_newline: bool, to_stderr: bool ) -> Result<i64, ShellError>
Consume and print self data immediately.
no_newline
controls if we need to attach newline character to output.
to_stderr
controls if data is output to stderr, when the value is false, the data is output to stdout.
sourcepub fn print_not_formatted(
self,
engine_state: &EngineState,
no_newline: bool,
to_stderr: bool
) -> Result<i64, ShellError>
pub fn print_not_formatted( self, engine_state: &EngineState, no_newline: bool, to_stderr: bool ) -> Result<i64, ShellError>
Consume and print self data immediately.
Unlike [.print()
] does not call table
to format data and just prints it
one element on a line
no_newline
controls if we need to attach newline character to output.to_stderr
controls if data is output to stderr, when the value is false, the data is output to stdout.
Trait Implementations§
source§impl Debug for PipelineData
impl Debug for PipelineData
source§impl IntoIterator for PipelineData
impl IntoIterator for PipelineData
Auto Trait Implementations§
impl Freeze for PipelineData
impl !RefUnwindSafe for PipelineData
impl Send for PipelineData
impl !Sync for PipelineData
impl Unpin for PipelineData
impl !UnwindSafe for PipelineData
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<I> IntoInterruptiblePipelineData for Iwhere
I: IntoIterator + Send + 'static,
<I as IntoIterator>::IntoIter: Send + 'static,
<<I as IntoIterator>::IntoIter as Iterator>::Item: Into<Value>,
impl<I> IntoInterruptiblePipelineData for Iwhere
I: IntoIterator + Send + 'static,
<I as IntoIterator>::IntoIter: Send + 'static,
<<I as IntoIterator>::IntoIter as Iterator>::Item: Into<Value>,
fn into_pipeline_data(self, ctrlc: Option<Arc<AtomicBool>>) -> PipelineData
fn into_pipeline_data_with_metadata( self, metadata: impl Into<Option<PipelineMetadata>>, ctrlc: Option<Arc<AtomicBool>> ) -> PipelineData
source§impl<T> IntoSpanned for T
impl<T> IntoSpanned for T
source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moresource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more