Enum nu_protocol::PipelineData

source ·
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§

Implementations§

source§

impl PipelineData

source

pub fn empty() -> PipelineData

source

pub fn new_external_stream_with_only_exit_code(exit_code: i32) -> PipelineData

create a PipelineData::ByteStream with proper exit_code

It’s useful to break running without raising error at user level.

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 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.

source

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

source

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 OutDests 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 OutDests, the given PipelineData will be completely consumed and PipelineData::Empty will be returned.

source

pub fn drain(self) -> Result<Option<ExitStatus>, 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.

The span should be the span of the command or operation that would raise an error.

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 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 check_external_failed(self) -> Result<(Self, bool), ShellError>

Try to catch the external command 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 command run failed. If self is not PipelineData::ByteStream, the flag will be false.

Currently this will consume an external command to completion.

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<Option<ExitStatus>, 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

source§

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

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

impl From<ByteStream> for PipelineData

source§

fn from(stream: ByteStream) -> Self

Converts to this type from the input type.
source§

impl From<ListStream> for PipelineData

source§

fn from(stream: ListStream) -> Self

Converts to this type from the input type.
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<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
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>,

source§

impl<T> IntoSpanned for T

source§

fn into_spanned(self, span: Span) -> Spanned<T>

Wrap items together with a span into Spanned. Read more
source§

impl<D> OwoColorize for D

source§

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

Set the foreground color generically Read more
source§

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

Set the background color generically. Read more
source§

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

Change the foreground color to black
source§

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

Change the background color to black
source§

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

Change the foreground color to red
source§

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

Change the background color to red
source§

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

Change the foreground color to green
source§

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

Change the background color to green
source§

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

Change the foreground color to yellow
source§

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

Change the background color to yellow
source§

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

Change the foreground color to blue
source§

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

Change the background color to blue
source§

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

Change the foreground color to magenta
source§

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

Change the background color to magenta
source§

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

Change the foreground color to purple
source§

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

Change the background color to purple
source§

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

Change the foreground color to cyan
source§

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

Change the background color to cyan
source§

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

Change the foreground color to white
source§

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

Change the background color to white
source§

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

Change the foreground color to the terminal default
source§

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

Change the background color to the terminal default
source§

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

Change the foreground color to bright black
source§

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

Change the background color to bright black
source§

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

Change the foreground color to bright red
source§

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

Change the background color to bright red
source§

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

Change the foreground color to bright green
source§

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

Change the background color to bright green
source§

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

Change the foreground color to bright yellow
source§

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

Change the background color to bright yellow
source§

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

Change the foreground color to bright blue
source§

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

Change the background color to bright blue
source§

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

Change the foreground color to bright magenta
source§

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

Change the background color to bright magenta
source§

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

Change the foreground color to bright purple
source§

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

Change the background color to bright purple
source§

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

Change the foreground color to bright cyan
source§

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

Change the background color to bright cyan
source§

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

Change the foreground color to bright white
source§

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

Change the background color to bright white
source§

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

Make the text bold
source§

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

Make the text dim
source§

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

Make the text italicized
source§

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

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

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

Swap the foreground and background colors
source§

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

Hide the text
source§

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

Cross out the text
source§

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
source§

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
source§

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.
source§

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.
source§

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

Sets the foreground color to an RGB value.
source§

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

Sets the background color to an RGB value.
source§

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

Apply a runtime-determined style
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

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

Initializes a with the given initializer. Read more
source§

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

Dereferences the given pointer. Read more
source§

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

Mutably dereferences the given pointer. Read more
source§

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.