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

Fields

§exit_code: Option<ListStream>
§span: Span
§trim_end_newline: bool
§

Empty

Implementations§

source§

impl PipelineData

source

pub fn new_with_metadata( metadata: Option<PipelineMetadata>, span: Span ) -> PipelineData

source

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.

source

pub fn empty() -> PipelineData

source

pub fn metadata(&self) -> Option<PipelineMetadata>

source

pub fn set_metadata(self, metadata: Option<PipelineMetadata>) -> Self

source

pub fn is_nothing(&self) -> bool

source

pub fn span(&self) -> Option<Span>

PipelineData doesn’t always have a Span, but we can try!

source

pub fn into_value(self, span: Span) -> Value

source

pub fn drain(self) -> Result<(), ShellError>

source

pub fn drain_with_exit_code(self) -> Result<i64, ShellError>

source

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.

source

pub fn into_interruptible_iter( self, ctrlc: Option<Arc<AtomicBool>> ) -> PipelineIterator

source

pub fn collect_string( self, separator: &str, config: &Config ) -> Result<String, ShellError>

source

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.

source

pub fn follow_cell_path( self, cell_path: &[PathMember], head: Span, insensitive: bool ) -> Result<Value, ShellError>

source

pub fn upsert_cell_path( &mut self, cell_path: &[PathMember], callback: Box<dyn FnOnce(&Value) -> Value>, head: Span ) -> Result<(), ShellError>

source

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

source

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

source

pub fn filter<F>( self, f: F, ctrlc: Option<Arc<AtomicBool>> ) -> Result<PipelineData, ShellError>
where Self: Sized, F: FnMut(&Value) -> bool + 'static + Send,

source

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.

source

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]

source

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.

source

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl IntoIterator for PipelineData

§

type Item = Value

The type of the elements being iterated over.
§

type IntoIter = PipelineIterator

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<I> IntoInterruptiblePipelineData for I
where I: IntoIterator + Send + 'static, <I as IntoIterator>::IntoIter: Send + 'static, <<I as IntoIterator>::IntoIter as Iterator>::Item: Into<Value>,

§

impl<D> OwoColorize for D

§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
§

fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>

Change the foreground color to black
§

fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>

Change the background color to black
§

fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>

Change the foreground color to red
§

fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>

Change the background color to red
§

fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>

Change the foreground color to green
§

fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>

Change the background color to green
§

fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow
§

fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>

Change the background color to yellow
§

fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>

Change the foreground color to blue
§

fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>

Change the background color to blue
§

fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta
§

fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to magenta
§

fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple
§

fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to purple
§

fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan
§

fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>

Change the background color to cyan
§

fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>

Change the foreground color to white
§

fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>

Change the background color to white
§

fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>

Change the foreground color to the terminal default
§

fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>

Change the background color to the terminal default
§

fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black
§

fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>

Change the background color to bright black
§

fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red
§

fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>

Change the background color to bright red
§

fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green
§

fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>

Change the background color to bright green
§

fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow
§

fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>

Change the background color to bright yellow
§

fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue
§

fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>

Change the background color to bright blue
§

fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta
§

fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright magenta
§

fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple
§

fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright purple
§

fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan
§

fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>

Change the background color to bright cyan
§

fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white
§

fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>

Change the background color to bright white
§

fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>

Make the text bold
§

fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>

Make the text dim
§

fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>

Make the text italicized
§

fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>

Make the text italicized
Make the text blink
Make the text blink (but fast!)
§

fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>

Swap the foreground and background colors
§

fn hidden<'a>(&'a self) -> HiddenDisplay<'a, Self>

Hide the text
§

fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>

Cross out the text
§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either 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,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.