pub enum PipelineData {
Empty,
Value(Value, Option<PipelineMetadata>),
ListStream(ListStream, Option<PipelineMetadata>),
ByteStream(ByteStream, Option<PipelineMetadata>),
}
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§
Empty
Value(Value, Option<PipelineMetadata>)
ListStream(ListStream, Option<PipelineMetadata>)
ByteStream(ByteStream, Option<PipelineMetadata>)
Implementations§
Source§impl PipelineData
impl PipelineData
pub fn empty() -> PipelineData
pub fn metadata(&self) -> Option<PipelineMetadata>
pub fn set_metadata(self, metadata: Option<PipelineMetadata>) -> PipelineData
pub fn is_nothing(&self) -> bool
Sourcepub fn with_span(self, span: Span) -> PipelineData
pub fn with_span(self, span: Span) -> PipelineData
Change the span of the PipelineData
.
Returns Value(Nothing)
with the given span if it was PipelineData::Empty
.
Sourcepub fn get_type(&self) -> Type
pub fn get_type(&self) -> Type
Get a type that is representative of the PipelineData
.
The type returned here makes no effort to collect a stream, so it may be a different type
than would be returned by Value::get_type()
on the result of
.into_value()
.
Specifically, a ListStream
results in list stream
rather than
the fully complete list
type (which would require knowing the contents),
and a ByteStream
with unknown type results in
any
rather than string
or binary
.
pub fn into_value(self, span: Span) -> Result<Value, ShellError>
Sourcepub fn try_into_stream(
self,
engine_state: &EngineState,
) -> Result<PipelineData, PipelineData>
pub fn try_into_stream( self, engine_state: &EngineState, ) -> Result<PipelineData, PipelineData>
Converts any Value
variant that can be represented as a stream into its stream variant.
This means that lists and ranges are converted into list streams, and strings and binary are converted into byte streams.
Returns an Err
with the original stream if the variant couldn’t be converted to a stream
variant. If the variant is already a stream variant, it is returned as-is.
Sourcepub fn write_to(self, dest: impl Write) -> Result<(), ShellError>
pub fn write_to(self, dest: impl Write) -> Result<(), ShellError>
Drain and write this PipelineData
to dest
.
Values are converted to bytes and separated by newlines if this is a ListStream
.
Sourcepub fn drain_to_out_dests(
self,
engine_state: &EngineState,
stack: &mut Stack,
) -> Result<PipelineData, ShellError>
pub fn drain_to_out_dests( self, engine_state: &EngineState, stack: &mut Stack, ) -> Result<PipelineData, ShellError>
Drain this PipelineData
according to the current stdout OutDest
s in stack
.
For OutDest::Pipe
and OutDest::PipeSeparate
, this will return the PipelineData
as is. For OutDest::Value
, this will collect into a value and return it. For
OutDest::Print
, the PipelineData
is drained and printed. Otherwise, the
PipelineData
is drained, but only printed if it is the output of an external command.
pub fn drain(self) -> Result<(), 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.
The span
should be the span of the command or operation that would raise an error.
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>
Sourcepub fn map<F>(self, f: F, signals: &Signals) -> Result<PipelineData, ShellError>
pub fn map<F>(self, f: F, signals: &Signals) -> 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,
signals: &Signals,
) -> Result<PipelineData, ShellError>where
PipelineData: 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,
signals: &Signals,
) -> Result<PipelineData, ShellError>where
PipelineData: 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, signals: &Signals, ) -> Result<PipelineData, ShellError>
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<(), ShellError>
pub fn print( self, engine_state: &EngineState, stack: &mut Stack, no_newline: bool, to_stderr: bool, ) -> Result<(), 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_raw(
self,
engine_state: &EngineState,
no_newline: bool,
to_stderr: bool,
) -> Result<(), ShellError>
pub fn print_raw( self, engine_state: &EngineState, no_newline: bool, to_stderr: bool, ) -> Result<(), ShellError>
Consume and print self data without any extra formatting.
This does not use the table
command to format data, and also prints binary values and
streams in their raw format without generating a hexdump first.
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.
pub fn unsupported_input_error( self, expected_type: impl Into<String>, span: Span, ) -> ShellError
Trait Implementations§
Source§impl Debug for PipelineData
impl Debug for PipelineData
Source§impl From<ByteStream> for PipelineData
impl From<ByteStream> for PipelineData
Source§fn from(stream: ByteStream) -> PipelineData
fn from(stream: ByteStream) -> PipelineData
Source§impl From<ListStream> for PipelineData
impl From<ListStream> for PipelineData
Source§fn from(stream: ListStream) -> PipelineData
fn from(stream: ListStream) -> PipelineData
Source§impl IntoIterator for PipelineData
impl IntoIterator for PipelineData
Source§type IntoIter = PipelineIterator
type IntoIter = PipelineIterator
Source§fn into_iter(self) -> <PipelineData as IntoIterator>::IntoIter
fn into_iter(self) -> <PipelineData as IntoIterator>::IntoIter
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, span: Span, signals: Signals) -> PipelineData
fn into_pipeline_data_with_metadata( self, span: Span, signals: Signals, metadata: impl Into<Option<PipelineMetadata>>, ) -> 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