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
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 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,
ignore_errors: 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>where
Self: Sized,
F: FnMut(Value) -> Value + 'static + Send,
pub fn map<F>(
self,
f: F,
ctrlc: Option<Arc<AtomicBool>>
) -> Result<PipelineData, ShellError>where
Self: Sized,
F: FnMut(Value) -> Value + 'static + Send,
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>where
Self: Sized,
F: FnMut(&Value) -> bool + 'static + Send,
sourcepub fn is_external_failed(self) -> (Self, bool)
pub fn is_external_failed(self) -> (Self, bool)
Try to catch external stream exit status and detect if it runs to failed.
This is useful to commands with semicolon, we can detect errors early to avoid commands after semicolon running.
Returns self and a flag indicates if the external stream runs to failed.
If self
is not Pipeline::ExternalStream, the flag will be false.
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.
Trait Implementations§
source§impl Debug for PipelineData
impl Debug for PipelineData
source§impl IntoIterator for PipelineData
impl IntoIterator for PipelineData
Auto Trait Implementations§
impl !RefUnwindSafe for PipelineData
impl Send for PipelineData
impl !Sync for PipelineData
impl Unpin for PipelineData
impl !UnwindSafe for PipelineData
Blanket Implementations§
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§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 more§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