ListStream touchup (#12524)

# Description

Does some misc changes to `ListStream`:
- Moves it into its own module/file separate from `RawStream`.
- `ListStream`s now have an associated `Span`.
- This required changes to `ListStreamInfo` in `nu-plugin`. Note sure if
this is a breaking change for the plugin protocol.
- Hides the internals of `ListStream` but also adds a few more methods.
- This includes two functions to more easily alter a stream (these take
a `ListStream` and return a `ListStream` instead of having to go through
the whole `into_pipeline_data(..)` route).
  -  `map`: takes a `FnMut(Value) -> Value`
  - `modify`: takes a function to modify the inner stream.
This commit is contained in:
Ian Manske
2024-05-05 16:00:59 +00:00
committed by GitHub
parent 3143ded374
commit e879d4ecaf
106 changed files with 957 additions and 874 deletions

View File

@ -183,7 +183,7 @@ used as the next argument to the closure, otherwise generation stops.
Ok(iter
.flatten()
.into_pipeline_data(engine_state.ctrlc.clone()))
.into_pipeline_data(call.head, engine_state.ctrlc.clone()))
}
}

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::ListStream;
#[derive(Clone)]
pub struct Seq;
@ -119,36 +120,32 @@ pub fn run_seq(
let step = if free.len() > 2 { free[1] } else { 1.0 };
let last = { free[free.len() - 1] };
if !contains_decimals {
// integers only
Ok(PipelineData::ListStream(
nu_protocol::ListStream::from_stream(
IntSeq {
count: first as i64,
step: step as i64,
last: last as i64,
span,
},
engine_state.ctrlc.clone(),
),
None,
))
let stream = if !contains_decimals {
ListStream::new(
IntSeq {
count: first as i64,
step: step as i64,
last: last as i64,
span,
},
span,
engine_state.ctrlc.clone(),
)
} else {
// floats
Ok(PipelineData::ListStream(
nu_protocol::ListStream::from_stream(
FloatSeq {
first,
step,
last,
index: 0,
span,
},
engine_state.ctrlc.clone(),
),
None,
))
}
ListStream::new(
FloatSeq {
first,
step,
last,
index: 0,
span,
},
span,
engine_state.ctrlc.clone(),
)
};
Ok(stream.into())
}
struct FloatSeq {