allow collect warning

This commit is contained in:
Fernando Herrera 2021-09-23 20:39:42 +01:00
parent 772f8598dd
commit 04990eeba4

View File

@ -29,17 +29,22 @@ impl Command for Lines {
input: Value, input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> { ) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
let value = match input { let value = match input {
#[allow(clippy::needless_collect)]
// Collect is needed because the string may not live long enough for
// the Rc structure to continue using it. If split could take ownership
// of the split values, then this wouldn't be needed
Value::String { val, span } => { Value::String { val, span } => {
let iter = val let lines = val
.split(SPLIT_CHAR) .split(SPLIT_CHAR)
.map(|s| Value::String { .map(|s| s.to_string())
val: s.into(), .collect::<Vec<String>>();
span,
}) let iter = lines
.collect::<Vec<Value>>(); // <----- how to avoid collecting? .into_iter()
.map(move |s| Value::String { val: s, span });
Value::Stream { Value::Stream {
stream: ValueStream(Rc::new(RefCell::new(iter.into_iter()))), stream: ValueStream(Rc::new(RefCell::new(iter))),
span: Span::unknown(), span: Span::unknown(),
} }
} }
@ -67,11 +72,10 @@ impl Command for Lines {
None None
} }
}) })
.flatten() .flatten();
.collect::<Vec<Value>>(); // <----- how to avoid collecting?
Value::Stream { Value::Stream {
stream: ValueStream(Rc::new(RefCell::new(iter.into_iter()))), stream: ValueStream(Rc::new(RefCell::new(iter))),
span: Span::unknown(), span: Span::unknown(),
} }
} }