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>,
},
}
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
Implementations
sourceimpl PipelineData
impl PipelineData
pub fn new(span: Span) -> PipelineData
pub fn new_with_metadata(
metadata: Option<PipelineMetadata>,
span: Span
) -> 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
pub fn into_interruptible_iter(
self,
ctrlc: Option<Arc<AtomicBool>>
) -> PipelineIteratorⓘNotable traits for PipelineIteratorimpl Iterator for PipelineIterator type Item = Value;
pub fn collect_string(
self,
separator: &str,
config: &Config
) -> Result<String, ShellError>
pub fn follow_cell_path(
self,
cell_path: &[PathMember],
head: Span
) -> 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: 'static, F>(
self,
f: F,
ctrlc: Option<Arc<AtomicBool>>
) -> Result<PipelineData, ShellError> where
Self: Sized,
U: IntoIterator<Item = Value>,
<U as IntoIterator>::IntoIter: 'static + Send,
F: FnMut(Value) -> U + 'static + Send,
pub fn flat_map<U: 'static, F>(
self,
f: F,
ctrlc: Option<Arc<AtomicBool>>
) -> Result<PipelineData, ShellError> where
Self: Sized,
U: IntoIterator<Item = Value>,
<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,
Trait Implementations
sourceimpl Debug for PipelineData
impl Debug for PipelineData
sourceimpl 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more